Skip to content

Commit 29a083c

Browse files
authored
doc: clarify how fs.Dirent file types are determined
The file type of a directory entry returned by fs.readdir() or fs.opendir() is the type reported by the operating system's directory listing. Node.js falls back to lstat() only when the reported type is unknown, and some file systems may report a type that differs from what lstat() would return. Document this in the fs.Dirent class introduction, with fs.lstat() as the accurate alternative. Fixes: #30646 Signed-off-by: Julian Soreavis <julian.soreavis@gmail.com> PR-URL: #64532 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Jason Zhang <xzha4350@gmail.com>
1 parent b2b2b41 commit 29a083c

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

doc/api/fs.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7407,6 +7407,13 @@ Additionally, when [`fs.readdir()`][] or [`fs.readdirSync()`][] is called with
74077407
the `withFileTypes` option set to `true`, the resulting array is filled with
74087408
{fs.Dirent} objects, rather than strings or {Buffer}s.
74097409
7410+
When a directory is read, such as with [`fs.readdir()`][] or
7411+
[`fs.opendir()`][], the file type of each entry is the type reported by the
7412+
operating system and may depend on the file system; for example, some file
7413+
systems may report a type that differs from what [`fs.lstat()`][] returns.
7414+
Node.js calls [`fs.lstat()`][] on such an entry only when the reported type
7415+
is unknown. Use [`fs.lstat()`][] when an accurate file type is required.
7416+
74107417
#### `dirent.isBlockDevice()`
74117418
74127419
<!-- YAML

0 commit comments

Comments
 (0)