@@ -283,6 +283,92 @@ synchronous use libuv's threadpool, which can have surprising and negative
283283performance implications for some applications. See the
284284[ ` UV_THREADPOOL_SIZE ` ] [ ] documentation for more information.
285285
286+ ## Class: fs.Dirent
287+ <!-- YAML
288+ added: REPLACEME
289+ -->
290+
291+ When [ ` fs.readdir() ` ] [ ] or [ ` fs.readdirSync() ` ] [ ] is called with the
292+ ` withFileTypes ` option set to ` true ` , the resulting array is filled with
293+ ` fs.Dirent ` objects, rather than strings or ` Buffers ` .
294+
295+ ### dirent.isBlockDevice()
296+ <!-- YAML
297+ added: REPLACEME
298+ -->
299+
300+ * Returns: {boolean}
301+
302+ Returns ` true ` if the ` fs.Dirent ` object describes a block device.
303+
304+ ### dirent.isCharacterDevice()
305+ <!-- YAML
306+ added: REPLACEME
307+ -->
308+
309+ * Returns: {boolean}
310+
311+ Returns ` true ` if the ` fs.Dirent ` object describes a character device.
312+
313+ ### dirent.isDirectory()
314+ <!-- YAML
315+ added: REPLACEME
316+ -->
317+
318+ * Returns: {boolean}
319+
320+ Returns ` true ` if the ` fs.Dirent ` object describes a file system
321+ directory.
322+
323+ ### dirent.isFIFO()
324+ <!-- YAML
325+ added: REPLACEME
326+ -->
327+
328+ * Returns: {boolean}
329+
330+ Returns ` true ` if the ` fs.Dirent ` object describes a first-in-first-out
331+ (FIFO) pipe.
332+
333+ ### dirent.isFile()
334+ <!-- YAML
335+ added: REPLACEME
336+ -->
337+
338+ * Returns: {boolean}
339+
340+ Returns ` true ` if the ` fs.Dirent ` object describes a regular file.
341+
342+ ### dirent.isSocket()
343+ <!-- YAML
344+ added: REPLACEME
345+ -->
346+
347+ * Returns: {boolean}
348+
349+ Returns ` true ` if the ` fs.Dirent ` object describes a socket.
350+
351+ ### dirent.isSymbolicLink()
352+ <!-- YAML
353+ added: REPLACEME
354+ -->
355+
356+ * Returns: {boolean}
357+
358+ Returns ` true ` if the ` fs.Dirent ` object describes a symbolic link.
359+
360+
361+ ### dirent.name
362+ <!-- YAML
363+ added: REPLACEME
364+ -->
365+
366+ * {string|Buffer}
367+
368+ The file name that this ` fs.Dirent ` object refers to. The type of this
369+ value is determined by the ` options.encoding ` passed to [ ` fs.readdir() ` ] [ ] or
370+ [ ` fs.readdirSync() ` ] [ ] .
371+
286372## Class: fs.FSWatcher
287373<!-- YAML
288374added: v0.5.8
@@ -2299,9 +2385,10 @@ changes:
22992385* ` path ` {string|Buffer|URL}
23002386* ` options ` {string|Object}
23012387 * ` encoding ` {string} ** Default:** ` 'utf8' `
2388+ * ` withFileTypes ` {boolean} ** Default:** ` false `
23022389* ` callback ` {Function}
23032390 * ` err ` {Error}
2304- * ` files ` {string[ ] |Buffer[ ] }
2391+ * ` files ` {string[ ] |Buffer[ ] |fs.Dirent [ ] }
23052392
23062393Asynchronous readdir(3). Reads the contents of a directory.
23072394The callback gets two arguments ` (err, files) ` where ` files ` is an array of
@@ -2312,6 +2399,9 @@ object with an `encoding` property specifying the character encoding to use for
23122399the filenames passed to the callback. If the ` encoding ` is set to ` 'buffer' ` ,
23132400the filenames returned will be passed as ` Buffer ` objects.
23142401
2402+ If ` options.withFileTypes ` is set to ` true ` , the ` files ` array will contain
2403+ [ ` fs.Dirent ` ] [ ] objects.
2404+
23152405## fs.readdirSync(path[ , options] )
23162406<!-- YAML
23172407added: v0.1.21
@@ -2325,7 +2415,8 @@ changes:
23252415* ` path ` {string|Buffer|URL}
23262416* ` options ` {string|Object}
23272417 * ` encoding ` {string} ** Default:** ` 'utf8' `
2328- * Returns: {string[ ] } An array of filenames excluding ` '.' ` and ` '..' ` .
2418+ * ` withFileTypes ` {boolean} ** Default:** ` false `
2419+ * Returns: {string[ ] |Buffer[ ] |fs.Dirent[ ] }
23292420
23302421Synchronous readdir(3).
23312422
@@ -2334,6 +2425,9 @@ object with an `encoding` property specifying the character encoding to use for
23342425the filenames returned. If the ` encoding ` is set to ` 'buffer' ` ,
23352426the filenames returned will be passed as ` Buffer ` objects.
23362427
2428+ If ` options.withFileTypes ` is set to ` true ` , the result will contain
2429+ [ ` fs.Dirent ` ] [ ] objects.
2430+
23372431## fs.readFile(path[ , options] , callback)
23382432<!-- YAML
23392433added: v0.1.29
@@ -4611,6 +4705,7 @@ the file contents.
46114705[ `WriteStream` ] : #fs_class_fs_writestream
46124706[ `EventEmitter` ] : events.html
46134707[ `event ports` ] : http://illumos.org/man/port_create
4708+ [ `fs.Dirent` ] : #fs_class_fs_dirent
46144709[ `fs.FSWatcher` ] : #fs_class_fs_fswatcher
46154710[ `fs.Stats` ] : #fs_class_fs_stats
46164711[ `fs.access()` ] : #fs_fs_access_path_mode_callback
@@ -4626,6 +4721,8 @@ the file contents.
46264721[ `fs.mkdtemp()` ] : #fs_fs_mkdtemp_prefix_options_callback
46274722[ `fs.open()` ] : #fs_fs_open_path_flags_mode_callback
46284723[ `fs.read()` ] : #fs_fs_read_fd_buffer_offset_length_position_callback
4724+ [ `fs.readdir()` ] : #fs_fs_readdir_path_options_callback
4725+ [ `fs.readdirSync()` ] : #fs_fs_readdirsync_path_options
46294726[ `fs.readFile()` ] : #fs_fs_readfile_path_options_callback
46304727[ `fs.readFileSync()` ] : #fs_fs_readfilesync_path_options
46314728[ `fs.realpath()` ] : #fs_fs_realpath_path_options_callback
0 commit comments