-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: add FileHandle.prototype.readableWebStream()
Adds an experimental `readableWebStream()` method to `FileHandle` that returns a web `ReadableStream` Signed-off-by: James M Snell <[email protected]>
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const { | ||
readFileSync, | ||
} = require('fs'); | ||
|
||
const { | ||
open, | ||
} = require('fs/promises'); | ||
|
||
const check = readFileSync(__filename, { encoding: 'utf8' }); | ||
|
||
(async () => { | ||
const dec = new TextDecoder(); | ||
const file = await open(__filename); | ||
let data = ''; | ||
for await (const chunk of file.readableWebStream()) | ||
data += dec.decode(chunk); | ||
|
||
assert.strictEqual(check, data); | ||
|
||
assert.throws(() => file.readableWebStream(), { | ||
code: 'ERR_INVALID_STATE', | ||
}); | ||
|
||
await file.close(); | ||
})().then(common.mustCall()); | ||
|
||
(async () => { | ||
const file = await open(__filename); | ||
await file.close(); | ||
|
||
assert.throws(() => file.readableWebStream(), { | ||
code: 'ERR_INVALID_STATE', | ||
}); | ||
})().then(common.mustCall()); | ||
|
||
(async () => { | ||
const file = await open(__filename); | ||
file.close(); | ||
|
||
assert.throws(() => file.readableWebStream(), { | ||
code: 'ERR_INVALID_STATE', | ||
}); | ||
})().then(common.mustCall()); |