diff options
author | Jeremiah Senkpiel <fishrock123@rocketmail.com> | 2019-08-27 17:14:27 -0700 |
---|---|---|
committer | Jeremiah Senkpiel <fishrock123@rocketmail.com> | 2019-10-08 10:34:48 -0700 |
commit | cbd8d715b2286e5726e6988921f5c870cbf74127 (patch) | |
tree | 20c878fd9d7882f2a5b43718a0b3daad4a9a0255 /doc/api/errors.md | |
parent | 064e111515185529b6f943dc66929440557fd609 (diff) | |
download | android-node-v8-cbd8d715b2286e5726e6988921f5c870cbf74127.tar.gz android-node-v8-cbd8d715b2286e5726e6988921f5c870cbf74127.tar.bz2 android-node-v8-cbd8d715b2286e5726e6988921f5c870cbf74127.zip |
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: https://github.com/nodejs/node-v0.x-archive/issues/388
Refs: https://github.com/nodejs/node/issues/583
Refs: https://github.com/libuv/libuv/pull/2057
PR-URL: https://github.com/nodejs/node/pull/29349
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
Diffstat (limited to 'doc/api/errors.md')
-rw-r--r-- | doc/api/errors.md | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/doc/api/errors.md b/doc/api/errors.md index e13e25827e..8c86012630 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -826,6 +826,11 @@ A signing `key` was not provided to the [`sign.sign()`][] method. [`crypto.timingSafeEqual()`][] was called with `Buffer`, `TypedArray`, or `DataView` arguments of different lengths. +<a id="ERR_DIR_CLOSED"></a> +### ERR_DIR_CLOSED + +The [`fs.Dir`][] was previously closed. + <a id="ERR_DNS_SET_SERVERS_FAILED"></a> ### ERR_DNS_SET_SERVERS_FAILED @@ -2388,6 +2393,7 @@ such as `process.stdout.on('data')`. [`dgram.disconnect()`]: dgram.html#dgram_socket_disconnect [`dgram.remoteAddress()`]: dgram.html#dgram_socket_remoteaddress [`errno`(3) man page]: http://man7.org/linux/man-pages/man3/errno.3.html +[`fs.Dir`]: fs.html#fs_class_fs_dir [`fs.readFileSync`]: fs.html#fs_fs_readfilesync_path_options [`fs.readdir`]: fs.html#fs_fs_readdir_path_options_callback [`fs.symlink()`]: fs.html#fs_fs_symlink_target_path_type_callback |