diff --git a/doc/api/fs.md b/doc/api/fs.md index 07d5ec9a439835..cbef98d6233306 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -1236,6 +1236,44 @@ by [Naming Files, Paths, and Namespaces][]. Under NTFS, if the filename contains a colon, Node.js will open a file system stream, as described by [this MSDN page][MSDN-Using-Streams]. +### `fsPromises.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/promises'; + +const blob = await openAsBlob('the.file.txt'); +const ab = await blob.arrayBuffer(); +blob.stream(); +``` + +```cjs +const { openAsBlob } = require('node:fs/promises'); + +(async () => { + const blob = await openAsBlob('the.file.txt'); + const ab = await blob.arrayBuffer(); + blob.stream(); +})(); +``` + ### `fsPromises.opendir(path[, options])` > Stability: 1 - Experimental @@ -3412,32 +3454,12 @@ added: v19.8.0 * `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(); -``` +* `callback` {Function} + * `err` {Error} + * `blob` {Blob} -```cjs -const { openAsBlob } = require('node:fs'); - -(async () => { - const blob = await openAsBlob('the.file.txt'); - const ab = await blob.arrayBuffer(); - blob.stream(); -})(); -``` +For detailed information, see the documentation of the Promises version +of this API: [`fsPromises.openAsBlob()`][]. ### `fs.opendir(path[, options], callback)` @@ -5602,6 +5624,22 @@ this API: [`fs.mkdtemp()`][]. The optional `options` argument can be a string specifying an encoding, or an object with an `encoding` property specifying the character encoding to use. +### `fs.openAsBlobSync(path[, options])` + + + +> Stability: 1 - Experimental + +* `path` {string|Buffer|URL} +* `options` {Object} + * `type` {string} An optional mime type for the blob. +* Returns: {Blob} + +For detailed information, see the documentation of the Promises version +of this API: [`fsPromises.openAsBlob()`][]. + ### `fs.opendirSync(path[, options])`