Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: add more info to fs.Dir and fix typos #29890

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,6 @@ A class representing a directory stream.

Created by [`fs.opendir()`][], [`fs.opendirSync()`][], or [`fsPromises.opendir()`][].

Example using async interation:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the typo in this one be fixed too instead of removing the line?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the line should be removed. In general, I dislike putting for example: and similar stuff before code that is obviously an example.


```js
const fs = require('fs');

Expand Down Expand Up @@ -356,13 +354,13 @@ Subsequent reads will result in errors.
added: REPLACEME
-->

* Returns: {Promise} containing {fs.Dirent}
* Returns: {Promise} containing {fs.Dirent|null}

Asynchronously read the next directory entry via readdir(3) as an
[`fs.Dirent`][].

A `Promise` is returned that will be resolved with a [Dirent][] after the read
is completed.
After the read is completed, a `Promise` is returned that will be resolved with
an [`fs.Dirent`][], or `null` if there are no more directory entries to read.

_Directory entries returned by this function are in no particular order as
provided by the operating system's underlying directory mechanisms._
Expand All @@ -374,12 +372,13 @@ added: REPLACEME

* `callback` {Function}
* `err` {Error}
* `dirent` {fs.Dirent}
* `dirent` {fs.Dirent|null}

Asynchronously read the next directory entry via readdir(3) as an
[`fs.Dirent`][].

The `callback` will be called with a [Dirent][] after the read is completed.
After the read is completed, the `callback` will be called with an
[`fs.Dirent`][], or `null` if there are no more directory entries to read.

_Directory entries returned by this function are in no particular order as
provided by the operating system's underlying directory mechanisms._
Expand All @@ -389,11 +388,13 @@ provided by the operating system's underlying directory mechanisms._
added: REPLACEME
-->

* Returns: {fs.Dirent}
* Returns: {fs.Dirent|null}

Synchronously read the next directory entry via readdir(3) as an
[`fs.Dirent`][].

If there are no more directory entries to read, `null` will be returned.

_Directory entries returned by this function are in no particular order as
provided by the operating system's underlying directory mechanisms._

Expand All @@ -402,7 +403,15 @@ provided by the operating system's underlying directory mechanisms._
added: REPLACEME
-->

* Returns: {AsyncIterator} to fully iterate over all entries in the directory.
* Returns: {AsyncIterator} of {fs.Dirent}

Asynchronously iterates over the directory via readdir(3) until all entries have
been read.

Entries returned by the async iterator are always an [`fs.Dirent`][].
The `null` case from `dir.read()` is handled internally.

See [`fs.Dir`][] for an example.

_Directory entries returned by this iterator are in no particular order as
provided by the operating system's underlying directory mechanisms._
Expand Down Expand Up @@ -4825,7 +4834,7 @@ and cleaning up the directory.
The `encoding` option sets the encoding for the `path` while opening the
directory and subsequent read operations.

Example using async interation:
Example using async iteration:

```js
const fs = require('fs');
Expand Down