diff --git a/doc/api/fs.md b/doc/api/fs.md index 865813069e16b1..5fd4cfeefb504d 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -3324,6 +3324,45 @@ a colon, Node.js will open a file system stream, as described by Functions based on `fs.open()` exhibit this behavior as well: `fs.writeFile()`, `fs.readFile()`, etc. +### `fs.openAsBlob(path[, options])` + + + +> Stability: 1 - Experimental + +* `path` {string|Buffer|URL} +* `options` {Object} + * `type` {string} An optional mime type for the blob. +* Return: {Promise} containing {Blob} + +Returns a {Blob} whose data is backed by the given file. + +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. + +```mjs +import { openAsBlob } from 'node:fs'; + +const blob = await openAsBlob('the.file.txt'); +const ab = await blob.arrayBuffer(); +blob.stream(); +``` + +```cjs +const { openAsBlob } = require('node:fs'); + +(async () => { + const blob = await openAsBlob('the.file.txt'); + const ab = await blob.arrayBuffer(); + blob.stream(); +})(); +``` + ### `fs.opendir(path[, options], callback)`