diff options
author | James M Snell <jasnell@gmail.com> | 2021-07-09 23:22:36 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2021-07-15 23:43:20 +0300 |
commit | 6cd12be34765d9d618d063059b80ed11ee99bac5 (patch) | |
tree | 5b081e2136f6c4f7a4ff0cbb1629615c3c391d8f /doc/api | |
parent | e2a6399be742f53103474d9fc1e56fadf7f90ccc (diff) |
fs: add FileHandle.prototype.readableWebStream()
Adds an experimental `readableWebStream()` method to `FileHandle` that
returns a web `ReadableStream`
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/39331
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'doc/api')
-rw-r--r-- | doc/api/fs.md | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/doc/api/fs.md b/doc/api/fs.md index 181b0980313..72170f13193 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -302,6 +302,52 @@ 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.readableWebStream()` +<!-- YAML +added: REPLACEME +--> + +> Stability: 1 - Experimental + +* Returns: {ReadableStream} + +Returns a `ReadableStream` that may be used to read the files data. + +An error will be thrown if this method is called more than once or is called +after the `FileHandle` is closed or closing. + +```mjs +import { + open, +} from 'node:fs/promises'; + +const file = await open('./some/file/to/read'); + +for await (const chunk of file.readableWebStream()) + console.log(chunk); + +await file.close(); +``` + +```cjs +const { + open, +} = require('fs/promises'); + +(async () => { + const file = await open('./some/file/to/read'); + + for await (const chunk of file.readableWebStream()) + console.log(chunk); + + await file.close(); +})(); +``` + +While the `ReadableStream` will read the file to completion, it will not +close the `FileHandle` automatically. User code must still call the +`fileHandle.close()` method. + #### `filehandle.readFile(options)` <!-- YAML added: v10.0.0 |