fs.openAsBlob(path[, options])


稳定性: 1 - 实验性

返回一个其数据由给定文件支持的 <Blob>

【Returns a <Blob> whose data is backed by the given file.】

在创建 <Blob> 之后,文件不得修改。任何修改都会导致读取 <Blob> 数据时出现 DOMException 错误。在创建 Blob 时以及每次读取之前,需要对文件进行同步的状态检查操作,以检测文件数据是否已在磁盘上被修改。

【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();
})();