Skip to content

Commit

Permalink
fixup! fixup! fs: add FileHandle.prototype.readableStream()
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Jul 11, 2021
1 parent 84012da commit 770daa8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
6 changes: 3 additions & 3 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ Reads data from the file and stores that in the given buffer.
If the file is not modified concurrently, the end-of-file is reached when the
number of bytes read is zero.
#### `filehandle.readableStream()`
#### `filehandle.readableWebStream()`
<!-- YAML
added: REPLACEME
-->
Expand All @@ -323,7 +323,7 @@ import {

const file = await open('./some/file/to/read');

for await (const chunk of file.readableStream())
for await (const chunk of file.readableWebStream())
console.log(chunk);
```
Expand All @@ -335,7 +335,7 @@ const {
(async () => {
const file = await open('./some/file/to/read');

for await (const chunk of file.readableStream())
for await (const chunk of file.readableWebStream())
console.log(chunk);
})();
```
Expand Down
7 changes: 6 additions & 1 deletion lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,12 @@ class FileHandle extends EventEmitterMixin(JSTransferable) {
return this[kClosePromise];
}

readableStream() {
/**
* @typedef {import('../webstreams/readablestream').ReadableStream
* } ReadableStream
* @returns {ReadableStream}
*/
readableWebStream() {
if (this[kFd] === -1)
throw new ERR_INVALID_STATE('The FileHandle is closed');
if (this[kClosePromise])
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-filehandle-readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const check = readFileSync(__filename, { encoding: 'utf8' });
const dec = new TextDecoder();
const file = await open(__filename);
let data = '';
for await (const chunk of file.readableStream())
for await (const chunk of file.readableWebStream())
data += dec.decode(chunk);

assert.strictEqual(check, data);

assert.throws(() => file.readableStream(), {
assert.throws(() => file.readableWebStream(), {
code: 'ERR_INVALID_STATE',
});

Expand All @@ -33,7 +33,7 @@ const check = readFileSync(__filename, { encoding: 'utf8' });
const file = await open(__filename);
await file.close();

assert.throws(() => file.readableStream(), {
assert.throws(() => file.readableWebStream(), {
code: 'ERR_INVALID_STATE',
});
})().then(common.mustCall());
Expand All @@ -42,7 +42,7 @@ const check = readFileSync(__filename, { encoding: 'utf8' });
const file = await open(__filename);
file.close();

assert.throws(() => file.readableStream(), {
assert.throws(() => file.readableWebStream(), {
code: 'ERR_INVALID_STATE',
});
})().then(common.mustCall());

0 comments on commit 770daa8

Please sign in to comment.