filehandle.readableWebStream([options])
稳定性: 1 - 实验性的
¥Stability: 1 - Experimental
-
options<Object>-
type<string> | <undefined> 是否打开普通或'bytes'流。默认值:undefined¥
type<string> | <undefined> Whether to open a normal or a'bytes'stream. Default:undefined
-
-
¥Returns: <ReadableStream>
返回可用于读取文件数据的 ReadableStream。
¥Returns a ReadableStream that may be used to read the files data.
如果多次调用此方法或在 FileHandle 关闭中或关闭后调用该方法会报错。
¥An error will be thrown if this method is called more than once or is called
after the FileHandle is closed or closing.
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();const {
open,
} = require('node:fs/promises');
(async () => {
const file = await open('./some/file/to/read');
for await (const chunk of file.readableWebStream())
console.log(chunk);
await file.close();
})();虽然 ReadableStream 会读完文件,但不会自动关闭 FileHandle。用户代码仍然必须调用 fileHandle.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.