Skip to content

Commit

Permalink
fs: add FileHandle support to Read/WriteStream
Browse files Browse the repository at this point in the history
Adopt reviewing remarks by @addaleax and @Trott

Refs: nodejs#35922
  • Loading branch information
mmomtchev committed Dec 2, 2020
1 parent be4dc0b commit b9c8218
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -4720,7 +4720,7 @@ rejected.
added: REPLACEME
-->

The `'close'` event is emitted when the FileHandle and any of its underlying
The `'close'` event is emitted when the `FileHandle` and any of its underlying
resources (a file descriptor, for example) have been closed.

#### `filehandle.appendFile(data, options)`
Expand Down
20 changes: 10 additions & 10 deletions test/parallel/test-fs-read-stream-file-handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let output = '';
tmpdir.refresh();
fs.writeFileSync(file, input);

fs.promises.open(file, 'r').then((handle) => {
fs.promises.open(file, 'r').then(common.mustCall((handle) => {
handle.on('close', common.mustCall());
const stream = fs.createReadStream(null, { fd: handle });

Expand All @@ -24,36 +24,36 @@ fs.promises.open(file, 'r').then((handle) => {
}));

stream.on('close', common.mustCall());
});
}));

fs.promises.open(file, 'r').then((handle) => {
fs.promises.open(file, 'r').then(common.mustCall((handle) => {
handle.on('close', common.mustCall());
const stream = fs.createReadStream(null, { fd: handle });
stream.on('data', common.mustNotCall());
stream.on('close', common.mustCall());

handle.close();
});
}));

fs.promises.open(file, 'r').then((handle) => {
fs.promises.open(file, 'r').then(common.mustCall((handle) => {
handle.on('close', common.mustCall());
const stream = fs.createReadStream(null, { fd: handle });
stream.on('close', common.mustCall());

stream.on('data', common.mustCall(() => {
handle.close();
}));
});
}));

fs.promises.open(file, 'r').then((handle) => {
fs.promises.open(file, 'r').then(common.mustCall((handle) => {
handle.on('close', common.mustCall());
const stream = fs.createReadStream(null, { fd: handle });
stream.on('close', common.mustCall());

stream.close();
});
}));

fs.promises.open(file, 'r').then((handle) => {
fs.promises.open(file, 'r').then(common.mustCall((handle) => {
assert.throws(() => {
fs.createReadStream(null, { fd: handle, fs });
}, {
Expand All @@ -62,4 +62,4 @@ fs.promises.open(file, 'r').then((handle) => {
message: 'The FileHandle with fs method is not implemented'
});
handle.close();
});
}));
4 changes: 2 additions & 2 deletions test/parallel/test-fs-write-stream-file-handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const input = 'hello world';

tmpdir.refresh();

fs.promises.open(file, 'w+').then((handle) => {
fs.promises.open(file, 'w+').then(common.mustCall((handle) => {
handle.on('close', common.mustCall());
const stream = fs.createWriteStream(null, { fd: handle });

Expand All @@ -18,4 +18,4 @@ fs.promises.open(file, 'w+').then((handle) => {
const output = fs.readFileSync(file, 'utf-8');
assert.strictEqual(output, input);
}));
});
}));

0 comments on commit b9c8218

Please sign in to comment.