Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c56f765

Browse filesBrowse files
Fishrock123BridgeAR
authored andcommitted
fs: remove options.encoding from Dir.read*()
This is unlikely to be necessary in any case, and causes much unwarrented complexity when implementing further optimizations. Refs: #29893 (comment) PR-URL: #29908 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 2bcde83 commit c56f765
Copy full SHA for c56f765

File tree

Expand file treeCollapse file tree

2 files changed

+10
-27
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-27
lines changed
Open diff view settings
Collapse file

‎doc/api/fs.md‎

Copy file name to clipboardExpand all lines: doc/api/fs.md
+6-19Lines changed: 6 additions & 19 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -351,13 +351,11 @@ added: REPLACEME
351351
Synchronously close the directory's underlying resource handle.
352352
Subsequent reads will result in errors.
353353

354-
### dir.read([options])
354+
### dir.read()
355355
<!-- YAML
356356
added: REPLACEME
357357
-->
358358

359-
* `options` {Object}
360-
* `encoding` {string|null} **Default:** `'utf8'`
361359
* Returns: {Promise} containing {fs.Dirent}
362360

363361
Asynchronously read the next directory entry via readdir(3) as an
@@ -369,13 +367,11 @@ is completed.
369367
_Directory entries returned by this function are in no particular order as
370368
provided by the operating system's underlying directory mechanisms._
371369

372-
### dir.read([options, ]callback)
370+
### dir.read(callback)
373371
<!-- YAML
374372
added: REPLACEME
375373
-->
376374

377-
* `options` {Object}
378-
* `encoding` {string|null} **Default:** `'utf8'`
379375
* `callback` {Function}
380376
* `err` {Error}
381377
* `dirent` {fs.Dirent}
@@ -385,25 +381,19 @@ Asynchronously read the next directory entry via readdir(3) as an
385381

386382
The `callback` will be called with a [Dirent][] after the read is completed.
387383

388-
The `encoding` option sets the encoding of the `name` in the `dirent`.
389-
390384
_Directory entries returned by this function are in no particular order as
391385
provided by the operating system's underlying directory mechanisms._
392386

393-
### dir.readSync([options])
387+
### dir.readSync()
394388
<!-- YAML
395389
added: REPLACEME
396390
-->
397391

398-
* `options` {Object}
399-
* `encoding` {string|null} **Default:** `'utf8'`
400392
* Returns: {fs.Dirent}
401393

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

405-
The `encoding` option sets the encoding of the `name` in the `dirent`.
406-
407397
_Directory entries returned by this function are in no particular order as
408398
provided by the operating system's underlying directory mechanisms._
409399

@@ -2658,8 +2648,7 @@ Creates an [`fs.Dir`][], which contains all further functions for reading from
26582648
and cleaning up the directory.
26592649

26602650
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).
2651+
directory and subsequent read operations.
26632652

26642653
## fs.opendirSync(path[, options])
26652654
<!-- YAML
@@ -2677,8 +2666,7 @@ Creates an [`fs.Dir`][], which contains all further functions for reading from
26772666
and cleaning up the directory.
26782667

26792668
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).
2669+
directory and subsequent read operations.
26822670

26832671
## fs.read(fd, buffer, offset, length, position, callback)
26842672
<!-- YAML
@@ -4835,8 +4823,7 @@ Creates an [`fs.Dir`][], which contains all further functions for reading from
48354823
and cleaning up the directory.
48364824

48374825
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).
4826+
directory and subsequent read operations.
48404827

48414828
Example using async interation:
48424829

Collapse file

‎lib/internal/fs/dir.js‎

Copy file name to clipboardExpand all lines: lib/internal/fs/dir.js
+4-8Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,16 @@ class Dir {
4848
return this[kDirPath];
4949
}
5050

51-
read(options, callback) {
51+
read(callback) {
5252
if (this[kDirClosed] === true) {
5353
throw new ERR_DIR_CLOSED();
5454
}
5555

56-
callback = typeof options === 'function' ? options : callback;
5756
if (callback === undefined) {
58-
return this[kDirReadPromisified](options);
57+
return this[kDirReadPromisified]();
5958
} else if (typeof callback !== 'function') {
6059
throw new ERR_INVALID_CALLBACK(callback);
6160
}
62-
options = getOptions(options, this[kDirOptions]);
6361

6462
const req = new FSReqCallback();
6563
req.oncomplete = (err, result) => {
@@ -70,7 +68,7 @@ class Dir {
7068
};
7169

7270
this[kDirHandle].read(
73-
options.encoding,
71+
this[kDirOptions].encoding,
7472
req
7573
);
7674
}
@@ -80,11 +78,9 @@ class Dir {
8078
throw new ERR_DIR_CLOSED();
8179
}
8280

83-
options = getOptions(options, this[kDirOptions]);
84-
8581
const ctx = { path: this[kDirPath] };
8682
const result = this[kDirHandle].read(
87-
options.encoding,
83+
this[kDirOptions].encoding,
8884
undefined,
8985
ctx
9086
);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.