Skip to content

Commit 875d050

Browse files
committed
[Squash] feedback
1 parent 019d7fd commit 875d050

File tree

9 files changed

+133
-110
lines changed

9 files changed

+133
-110
lines changed

doc/api/fs.md

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -291,21 +291,21 @@ explicitly synchronous use libuv's threadpool, which can have surprising and
291291
negative performance implications for some applications, see the
292292
[`UV_THREADPOOL_SIZE`][] documentation for more information.
293293

294-
## class: fs.FD
294+
## class: fs.FileHandle
295295
<!-- YAML
296296
added: REPLACEME
297297
-->
298298

299-
An `fs.FD` object is a wrapper for a numeric file descriptor. Instances of
300-
`fs.FD` are distinct from numeric file descriptors in that, if the `fs.FD` is
301-
not explicitly closed using the `fd.close()` method, they will automatically
302-
close the file descriptor and will emit a process warning, thereby helping to
303-
prevent memory leaks.
299+
A `fs.FileHandle` object is a wrapper for a numeric file descriptor. Instances
300+
of `fs.FileHandle` are distinct from numeric file descriptors in that, if the
301+
`fs.FileHandle` is not explicitly closed using the `fd.close()` method, they
302+
will automatically close the file descriptor and will emit a process warning,
303+
thereby helping to prevent memory leaks.
304304

305-
Instances of the `fs.FD` object are created internally by the `fs.openFD()`
306-
and `fs.openFDSync()` methods.
305+
Instances of the `fs.FileHandle` object are created internally by the
306+
`fs.openFileHandle()` and `fs.openFileHandleSync()` methods.
307307

308-
### fd.close()
308+
### filehandle.close()
309309
<!-- YAML
310310
added: REPLACEME
311311
-->
@@ -316,18 +316,18 @@ added: REPLACEME
316316
Closes the file descriptor.
317317

318318
```js
319-
const fd = fs.openFDSync('thefile.txt', 'r');
320-
fd.close()
319+
const filehandle = fs.openFileHandleSync('thefile.txt', 'r');
320+
filehandle.close()
321321
.then(() => console.log('ok'))
322322
.catch(() => console.log('not ok'));
323323
```
324324

325-
### fd.fd
325+
### filehandle.fd
326326
<!-- YAML
327327
added: REPLACEME
328328
-->
329329

330-
Value: {number} The numeric file descriptor managed by the `FD` object.
330+
Value: {number} The numeric file descriptor managed by the `FileHandle` object.
331331

332332
## Class: fs.FSWatcher
333333
<!-- YAML
@@ -2107,7 +2107,7 @@ through `fs.open()` or `fs.writeFile()`) will fail with `EPERM`. Existing hidden
21072107
files can be opened for writing with the `r+` flag. A call to `fs.ftruncate()`
21082108
can be used to reset the file contents.
21092109

2110-
## fs.openFD(path, flags[, mode], callback)
2110+
## fs.openFileHandle(path, flags[, mode], callback)
21112111
<!-- YAML
21122112
added: REPLACEME
21132113
-->
@@ -2117,9 +2117,9 @@ added: REPLACEME
21172117
* `mode` {integer} **Default:** `0o666`
21182118
* `callback` {Function}
21192119
* `err` {Error}
2120-
* `fd` {[fs.FD][#fs_class_fs_fd]}
2120+
* `fd` {[fs.FileHandle][#fs_class_fs_filehandle]}
21212121

2122-
Asynchronous file open that returns an `fs.FD` object. See open(2).
2122+
Asynchronous file open that returns a `fs.FileHandle` object. See open(2).
21232123

21242124
The `flags` argument can be:
21252125

@@ -2136,8 +2136,9 @@ An exception occurs if the file does not exist.
21362136
the potentially stale local cache. It has a very real impact on I/O
21372137
performance so using this flag is not recommended unless it is needed.
21382138

2139-
Note that this doesn't turn `fs.openFD()` into a synchronous blocking call.
2140-
If synchronous operation is desired `fs.openFDSync()` should be used.
2139+
Note that this doesn't turn `fs.openFileHAndle()` into a synchronous blocking
2140+
call. If synchronous operation is desired `fs.openFileHandleSync()` should be
2141+
used.
21412142

21422143
* `'w'` - Open file for writing.
21432144
The file is created (if it does not exist) or truncated (if it exists).
@@ -2162,7 +2163,7 @@ The file is created if it does not exist.
21622163
`mode` sets the file mode (permission and sticky bits), but only if the file was
21632164
created. It defaults to `0o666` (readable and writable).
21642165

2165-
The callback gets two arguments `(err, fd)`.
2166+
The callback gets two arguments `(err, filehandle)`.
21662167

21672168
The exclusive flag `'x'` (`O_EXCL` flag in open(2)) ensures that `path` is newly
21682169
created. On POSIX systems, `path` is considered to exist even if it is a symlink
@@ -2178,20 +2179,20 @@ On Linux, positional writes don't work when the file is opened in append mode.
21782179
The kernel ignores the position argument and always appends the data to
21792180
the end of the file.
21802181

2181-
*Note*: The behavior of `fs.openFD()` is platform-specific for some flags. As
2182-
such, opening a directory on macOS and Linux with the `'a+'` flag - see example
2183-
below - will return an error. In contrast, on Windows and FreeBSD, a file
2184-
descriptor will be returned.
2182+
*Note*: The behavior of `fs.openFileHandle()` is platform-specific for some
2183+
flags. As such, opening a directory on macOS and Linux with the `'a+'` flag -
2184+
see example below - will return an error. In contrast, on Windows and FreeBSD,
2185+
a file descriptor will be returned.
21852186

21862187
```js
21872188
// macOS and Linux
2188-
fs.openFD('<directory>', 'a+', (err, fd) => {
2189+
fs.openFileHandle('<directory>', 'a+', (err, filehandle) => {
21892190
// => [Error: EISDIR: illegal operation on a directory, open <directory>]
21902191
});
21912192

21922193
// Windows and FreeBSD
2193-
fs.openFD('<directory>', 'a+', (err, fd) => {
2194-
// => null, <fd>
2194+
fs.openFileHandle('<directory>', 'a+', (err, filehandle) => {
2195+
// => null, <filehandle>
21952196
});
21962197
```
21972198

@@ -2201,22 +2202,22 @@ a colon, Node.js will open a file system stream, as described by
22012202
[this MSDN page][MSDN-Using-Streams].
22022203

22032204
*Note:* On Windows, opening an existing hidden file using the `w` flag (e.g.
2204-
using `fs.openFD()`) will fail with `EPERM`. Existing hidden
2205+
using `fs.openFileHandle()`) will fail with `EPERM`. Existing hidden
22052206
files can be opened for writing with the `r+` flag. A call to `fs.ftruncate()`
22062207
can be used to reset the file contents.
22072208

2208-
## fs.openFDSync(path, flags[, mode])
2209+
## fs.openFileHandleSync(path, flags[, mode])
22092210
<!-- YAML
22102211
added: REPLACEME
22112212
-->
22122213

22132214
* `path` {string|Buffer|URL}
22142215
* `flags` {string|number}
22152216
* `mode` {integer} **Default:** `0o666`
2216-
* Returns: {[fs.FD][#fs_class_fs_fd]}
2217+
* Returns: {[fs.FileHandle][#fs_class_fs_filehandle]}
22172218

2218-
Synchronous version of [`fs.openFD()`][]. Returns an `fs.FD` object representing
2219-
the file descriptor.
2219+
Synchronous version of [`fs.openFileHandle()`][]. Returns a `fs.FileHandle`
2220+
object representing the file descriptor.
22202221

22212222
## fs.openSync(path, flags[, mode])
22222223
<!-- YAML

lib/fs.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ fs.open = function(path, flags, mode, callback_) {
768768
req);
769769
};
770770

771-
fs.openFD = function(path, flags, mode, callback_) {
771+
fs.openFileHandle = function(path, flags, mode, callback_) {
772772
const callback = makeCallback(arguments[arguments.length - 1]);
773773
mode = modeNum(mode, 0o666);
774774

@@ -781,10 +781,10 @@ fs.openFD = function(path, flags, mode, callback_) {
781781
const req = new FSReqWrap();
782782
req.oncomplete = callback;
783783

784-
binding.openFD(pathModule.toNamespacedPath(path),
785-
stringToFlags(flags),
786-
mode,
787-
req);
784+
binding.openFileHandle(pathModule.toNamespacedPath(path),
785+
stringToFlags(flags),
786+
mode,
787+
req);
788788
};
789789

790790
fs.openSync = function(path, flags, mode) {
@@ -798,15 +798,15 @@ fs.openSync = function(path, flags, mode) {
798798
stringToFlags(flags), mode);
799799
};
800800

801-
fs.openFDSync = function(path, flags, mode) {
801+
fs.openFileHandleSync = function(path, flags, mode) {
802802
mode = modeNum(mode, 0o666);
803803
handleError((path = getPathFromURL(path)));
804804
nullCheck(path);
805805
validatePath(path);
806806
validateUint32(mode, 'mode');
807807

808-
return binding.openFD(pathModule.toNamespacedPath(path),
809-
stringToFlags(flags), mode);
808+
return binding.openFileHandle(pathModule.toNamespacedPath(path),
809+
stringToFlags(flags), mode);
810810
};
811811

812812
fs.read = function(fd, buffer, offset, length, position, callback) {

src/async_wrap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ namespace node {
3636
#define NODE_ASYNC_NON_CRYPTO_PROVIDER_TYPES(V) \
3737
V(NONE) \
3838
V(DNSCHANNEL) \
39-
V(FD) \
39+
V(FILEHANDLE) \
40+
V(FILEHANDLECLOSEREQ) \
4041
V(FSEVENTWRAP) \
4142
V(FSREQWRAP) \
4243
V(GETADDRINFOREQWRAP) \

src/env.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ class ModuleWrap;
282282
V(buffer_prototype_object, v8::Object) \
283283
V(context, v8::Context) \
284284
V(fd_constructor_template, v8::ObjectTemplate) \
285+
V(fdclose_constructor_template, v8::ObjectTemplate) \
285286
V(host_import_module_dynamically_callback, v8::Function) \
286287
V(http2ping_constructor_template, v8::ObjectTemplate) \
287288
V(http2stream_constructor_template, v8::ObjectTemplate) \

0 commit comments

Comments
 (0)