Please sign in to comment.
fs: introduce `opendir()` and `fs.Dir`
This adds long-requested methods for asynchronously interacting and iterating through directory entries by using `uv_fs_opendir`, `uv_fs_readdir`, and `uv_fs_closedir`. `fs.opendir()` and friends return an `fs.Dir`, which contains methods for doing reads and cleanup. `fs.Dir` also has the async iterator symbol exposed. The `read()` method and friends only return `fs.Dirent`s for this API. Having a entry type or doing a `stat` call is deemed to be necessary in the majority of cases, so just returning dirents seems like the logical choice for a new api. Reading when there are no more entries returns `null` instead of a dirent. However the async iterator hides that (and does automatic cleanup). The code lives in separate files from the rest of fs, this is done partially to prevent over-pollution of those (already very large) files, but also in the case of js allows loading into `fsPromises`. Due to async_hooks, this introduces a new handle type of `DIRHANDLE`. This PR does not attempt to make complete optimization of this feature. Notable future improvements include: - Moving promise work into C++ land like FileHandle. - Possibly adding `readv()` to do multi-entry directory reads. - Aliasing `fs.readdir` to `fs.scandir` and doing a deprecation. Refs: nodejs/node-v0.x-archive#388 Refs: #583 Refs: libuv/libuv#2057 PR-URL: #29349 Reviewed-By: Anna Henningsen <firstname.lastname@example.org> Reviewed-By: David Carlier <email@example.com>
- Loading branch information...
Showing with 1,165 additions and 119 deletions.
- +6 −0 doc/api/errors.md
- +214 −2 doc/api/fs.md
- +9 −18 lib/fs.js
- +1 −0 lib/internal/errors.js
- +201 −0 lib/internal/fs/dir.js
- +2 −0 lib/internal/fs/promises.js
- +43 −9 lib/internal/fs/utils.js
- +3 −0 node.gyp
- +1 −0 src/async_wrap.h
- +1 −0 src/env.h
- +1 −0 src/node_binding.cc
- +350 −0 src/node_dir.cc
- +60 −0 src/node_dir.h
- +0 −90 src/node_file.cc
- +89 −0 src/node_file.h
- +2 −0 test/parallel/test-bootstrap-modules.js
- +174 −0 test/parallel/test-fs-opendir.js
- +7 −0 test/sequential/test-async-wrap-getasyncid.js
- +1 −0 tools/doc/type-parser.js
Oops, something went wrong.