fs.openAsBlob(path[, options])
稳定性: 1 - 实验性的
¥Stability: 1 - Experimental
-
options
<Object>
返回一个 <Blob>,其数据由给定文件支持。
¥Returns a <Blob> whose data is backed by the given file.
创建 <Blob> 后不得修改该文件。任何修改都会导致读取 <Blob> 数据失败并出现 DOMException
错误。Blob
创建时和每次读取前对文件进行同步 stat 操作,以检测文件数据是否在磁盘上被修改。
¥The file must not be modified after the <Blob> is created. Any modifications
will cause reading the <Blob> data to fail with a DOMException
error.
Synchronous stat operations on the file when the Blob
is created, and before
each read in order to detect whether the file data has been modified on disk.
import { openAsBlob } from 'node:fs';
const blob = await openAsBlob('the.file.txt');
const ab = await blob.arrayBuffer();
blob.stream();
const { openAsBlob } = require('node:fs');
(async () => {
const blob = await openAsBlob('the.file.txt');
const ab = await blob.arrayBuffer();
blob.stream();
})();