@@ -284,13 +284,148 @@ synchronous use libuv's threadpool, which can have surprising and negative
284284performance implications for some applications. See the
285285[ ` UV_THREADPOOL_SIZE ` ] [ ] documentation for more information.
286286
287+ ## Class fs.Dir
288+ <!-- YAML
289+ added: REPLACEME
290+ -->
291+
292+ A class representing a directory stream.
293+
294+ Created by [ ` fs.opendir() ` ] [ ] , [ ` fs.opendirSync() ` ] [ ] , or [ ` fsPromises.opendir() ` ] [ ] .
295+
296+ Example using async interation:
297+
298+ ``` js
299+ const fs = require (' fs' );
300+
301+ async function print (path ) {
302+ const dir = await fs .promises .opendir (path);
303+ for await (const dirent of dir ) {
304+ console .log (dirent .name );
305+ }
306+ }
307+ print (' ./' ).catch (console .error );
308+ ```
309+
310+ ### dir.path
311+ <!-- YAML
312+ added: REPLACEME
313+ -->
314+
315+ * {string}
316+
317+ The read-only path of this directory as was provided to [ ` fs.opendir() ` ] [ ] ,
318+ [ ` fs.opendirSync() ` ] [ ] , or [ ` fsPromises.opendir() ` ] [ ] .
319+
320+ ### dir.close()
321+ <!-- YAML
322+ added: REPLACEME
323+ -->
324+
325+ * Returns: {Promise}
326+
327+ Asynchronously close the directory's underlying resource handle.
328+ Subsequent reads will result in errors.
329+
330+ A ` Promise ` is returned that will be resolved after the resource has been
331+ closed.
332+
333+ ### dir.close(callback)
334+ <!-- YAML
335+ added: REPLACEME
336+ -->
337+
338+ * ` callback ` {Function}
339+ * ` err ` {Error}
340+
341+ Asynchronously close the directory's underlying resource handle.
342+ Subsequent reads will result in errors.
343+
344+ The ` callback ` will be called after the resource handle has been closed.
345+
346+ ### dir.closeSync()
347+ <!-- YAML
348+ added: REPLACEME
349+ -->
350+
351+ Synchronously close the directory's underlying resource handle.
352+ Subsequent reads will result in errors.
353+
354+ ### dir.read([ options] )
355+ <!-- YAML
356+ added: REPLACEME
357+ -->
358+
359+ * ` options ` {Object}
360+ * ` encoding ` {string|null} ** Default:** ` 'utf8' `
361+ * Returns: {Promise} containing {fs.Dirent}
362+
363+ Asynchronously read the next directory entry via readdir(3) as an
364+ [ ` fs.Dirent ` ] [ ] .
365+
366+ A ` Promise ` is returned that will be resolved with a [ Dirent] [ ] after the read
367+ is completed.
368+
369+ _ Directory entries returned by this function are in no particular order as
370+ provided by the operating system's underlying directory mechanisms._
371+
372+ ### dir.read([ options, ] callback)
373+ <!-- YAML
374+ added: REPLACEME
375+ -->
376+
377+ * ` options ` {Object}
378+ * ` encoding ` {string|null} ** Default:** ` 'utf8' `
379+ * ` callback ` {Function}
380+ * ` err ` {Error}
381+ * ` dirent ` {fs.Dirent}
382+
383+ Asynchronously read the next directory entry via readdir(3) as an
384+ [ ` fs.Dirent ` ] [ ] .
385+
386+ The ` callback ` will be called with a [ Dirent] [ ] after the read is completed.
387+
388+ The ` encoding ` option sets the encoding of the ` name ` in the ` dirent ` .
389+
390+ _ Directory entries returned by this function are in no particular order as
391+ provided by the operating system's underlying directory mechanisms._
392+
393+ ### dir.readSync([ options] )
394+ <!-- YAML
395+ added: REPLACEME
396+ -->
397+
398+ * ` options ` {Object}
399+ * ` encoding ` {string|null} ** Default:** ` 'utf8' `
400+ * Returns: {fs.Dirent}
401+
402+ Synchronously read the next directory entry via readdir(3) as an
403+ [ ` fs.Dirent ` ] [ ] .
404+
405+ The ` encoding ` option sets the encoding of the ` name ` in the ` dirent ` .
406+
407+ _ Directory entries returned by this function are in no particular order as
408+ provided by the operating system's underlying directory mechanisms._
409+
410+ ### dir\[ Symbol.asyncIterator\] ()
411+ <!-- YAML
412+ added: REPLACEME
413+ -->
414+
415+ * Returns: {AsyncIterator} to fully iterate over all entries in the directory.
416+
417+ _ Directory entries returned by this iterator are in no particular order as
418+ provided by the operating system's underlying directory mechanisms._
419+
287420## Class: fs.Dirent
288421<!-- YAML
289422added: v10.10.0
290423-->
291424
292- When [ ` fs.readdir() ` ] [ ] or [ ` fs.readdirSync() ` ] [ ] is called with the
293- ` withFileTypes ` option set to ` true ` , the resulting array is filled with
425+ A representation of a directory entry, as returned by reading from an [ ` fs.Dir ` ] [ ] .
426+
427+ Additionally, when [ ` fs.readdir() ` ] [ ] or [ ` fs.readdirSync() ` ] [ ] is called with
428+ the ` withFileTypes ` option set to ` true ` , the resulting array is filled with
294429` fs.Dirent ` objects, rather than strings or ` Buffers ` .
295430
296431### dirent.isBlockDevice()
@@ -2505,6 +2640,46 @@ Returns an integer representing the file descriptor.
25052640For detailed information, see the documentation of the asynchronous version of
25062641this API: [ ` fs.open() ` ] [ ] .
25072642
2643+ ## fs.opendir(path[ , options] , callback)
2644+ <!-- YAML
2645+ added: REPLACEME
2646+ -->
2647+
2648+ * ` path ` {string|Buffer|URL}
2649+ * ` options ` {Object}
2650+ * ` encoding ` {string|null} ** Default:** ` 'utf8' `
2651+ * ` callback ` {Function}
2652+ * ` err ` {Error}
2653+ * ` dir ` {fs.Dir}
2654+
2655+ Asynchronously open a directory. See opendir(3).
2656+
2657+ Creates an [ ` fs.Dir ` ] [ ] , which contains all further functions for reading from
2658+ and cleaning up the directory.
2659+
2660+ The ` encoding ` option sets the encoding for the ` path ` while opening the
2661+ directory and subsequent read operations (unless otherwise overriden during
2662+ reads from the directory).
2663+
2664+ ## fs.opendirSync(path[ , options] )
2665+ <!-- YAML
2666+ added: REPLACEME
2667+ -->
2668+
2669+ * ` path ` {string|Buffer|URL}
2670+ * ` options ` {Object}
2671+ * ` encoding ` {string|null} ** Default:** ` 'utf8' `
2672+ * Returns: {fs.Dir}
2673+
2674+ Synchronously open a directory. See opendir(3).
2675+
2676+ Creates an [ ` fs.Dir ` ] [ ] , which contains all further functions for reading from
2677+ and cleaning up the directory.
2678+
2679+ The ` encoding ` option sets the encoding for the ` path ` while opening the
2680+ directory and subsequent read operations (unless otherwise overriden during
2681+ reads from the directory).
2682+
25082683## fs.read(fd, buffer, offset, length, position, callback)
25092684<!-- YAML
25102685added: v0.0.2
@@ -4644,6 +4819,39 @@ by [Naming Files, Paths, and Namespaces][]. Under NTFS, if the filename contains
46444819a colon, Node.js will open a file system stream, as described by
46454820[ this MSDN page] [ MSDN-Using-Streams ] .
46464821
4822+ ## fsPromises.opendir(path[ , options] )
4823+ <!-- YAML
4824+ added: REPLACEME
4825+ -->
4826+
4827+ * ` path ` {string|Buffer|URL}
4828+ * ` options ` {Object}
4829+ * ` encoding ` {string|null} ** Default:** ` 'utf8' `
4830+ * Returns: {Promise} containing {fs.Dir}
4831+
4832+ Asynchronously open a directory. See opendir(3).
4833+
4834+ Creates an [ ` fs.Dir ` ] [ ] , which contains all further functions for reading from
4835+ and cleaning up the directory.
4836+
4837+ The ` encoding ` option sets the encoding for the ` path ` while opening the
4838+ directory and subsequent read operations (unless otherwise overriden during
4839+ reads from the directory).
4840+
4841+ Example using async interation:
4842+
4843+ ``` js
4844+ const fs = require (' fs' );
4845+
4846+ async function print (path ) {
4847+ const dir = await fs .promises .opendir (path);
4848+ for await (const dirent of dir ) {
4849+ console .log (dirent .name );
4850+ }
4851+ }
4852+ print (' ./' ).catch (console .error );
4853+ ```
4854+
46474855### fsPromises.readdir(path[ , options] )
46484856<!-- YAML
46494857added: v10.0.0
@@ -5253,6 +5461,7 @@ the file contents.
52535461[ `UV_THREADPOOL_SIZE` ] : cli.html#cli_uv_threadpool_size_size
52545462[ `WriteStream` ] : #fs_class_fs_writestream
52555463[ `event ports` ] : https://illumos.org/man/port_create
5464+ [ `fs.Dir` ] : #fs_class_fs_dir
52565465[ `fs.Dirent` ] : #fs_class_fs_dirent
52575466[ `fs.FSWatcher` ] : #fs_class_fs_fswatcher
52585467[ `fs.Stats` ] : #fs_class_fs_stats
@@ -5269,6 +5478,8 @@ the file contents.
52695478[ `fs.mkdir()` ] : #fs_fs_mkdir_path_options_callback
52705479[ `fs.mkdtemp()` ] : #fs_fs_mkdtemp_prefix_options_callback
52715480[ `fs.open()` ] : #fs_fs_open_path_flags_mode_callback
5481+ [ `fs.opendir()` ] : #fs_fs_opendir_path_options_callback
5482+ [ `fs.opendirSync()` ] : #fs_fs_opendirsync_path_options
52725483[ `fs.read()` ] : #fs_fs_read_fd_buffer_offset_length_position_callback
52735484[ `fs.readFile()` ] : #fs_fs_readfile_path_options_callback
52745485[ `fs.readFileSync()` ] : #fs_fs_readfilesync_path_options
@@ -5284,6 +5495,7 @@ the file contents.
52845495[ `fs.write(fd, string...)` ] : #fs_fs_write_fd_string_position_encoding_callback
52855496[ `fs.writeFile()` ] : #fs_fs_writefile_file_data_options_callback
52865497[ `fs.writev()` ] : #fs_fs_writev_fd_buffers_position_callback
5498+ [ `fsPromises.opendir()` ] : #fs_fspromises_opendir_path_options
52875499[ `inotify(7)` ] : http://man7.org/linux/man-pages/man7/inotify.7.html
52885500[ `kqueue(2)` ] : https://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2
52895501[ `net.Socket` ] : net.html#net_class_net_socket
0 commit comments