filehandle.readableWebStream([options])
稳定性: 1 - 实验性
options<Object>type<string> | <undefined> 是否打开普通流或'bytes'流。 默认值:undefined
- 返回:<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.