Skip to content

Commit 20b9ef9

Browse files
Fishrock123BridgeAR
authored andcommitted
doc: add more info to fs.Dir and fix typos
Some doc bits / fixes which were missing from cbd8d71 PR-URL: #29890 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent c56f765 commit 20b9ef9

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

doc/api/fs.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,6 @@ A class representing a directory stream.
293293

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

296-
Example using async interation:
297-
298296
```js
299297
const fs = require('fs');
300298

@@ -356,13 +354,13 @@ Subsequent reads will result in errors.
356354
added: REPLACEME
357355
-->
358356

359-
* Returns: {Promise} containing {fs.Dirent}
357+
* Returns: {Promise} containing {fs.Dirent|null}
360358

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

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

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

375373
* `callback` {Function}
376374
* `err` {Error}
377-
* `dirent` {fs.Dirent}
375+
* `dirent` {fs.Dirent|null}
378376

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

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

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

392-
* Returns: {fs.Dirent}
391+
* Returns: {fs.Dirent|null}
393392

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

396+
If there are no more directory entries to read, `null` will be returned.
397+
397398
_Directory entries returned by this function are in no particular order as
398399
provided by the operating system's underlying directory mechanisms._
399400

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

405-
* Returns: {AsyncIterator} to fully iterate over all entries in the directory.
406+
* Returns: {AsyncIterator} of {fs.Dirent}
407+
408+
Asynchronously iterates over the directory via readdir(3) until all entries have
409+
been read.
410+
411+
Entries returned by the async iterator are always an [`fs.Dirent`][].
412+
The `null` case from `dir.read()` is handled internally.
413+
414+
See [`fs.Dir`][] for an example.
406415

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

4828-
Example using async interation:
4837+
Example using async iteration:
48294838

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

0 commit comments

Comments
 (0)