Skip to content

Commit dceb846

Browse files
1 parent bbb7758 commit dceb846

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

types/node/fs.d.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3900,6 +3900,31 @@ declare module 'fs' {
39003900
* @return The number of bytes read.
39013901
*/
39023902
export function readvSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
3903+
3904+
export interface OpenAsBlobOptions {
3905+
/**
3906+
* An optional mime type for the blob.
3907+
*
3908+
* @default 'undefined'
3909+
*/
3910+
type?: string | undefined;
3911+
}
3912+
3913+
/**
3914+
* Returns a Blob whose data is backed by the given file.
3915+
*
3916+
* The file must not be modified after the `Blob` is created.
3917+
* Any modifications will cause reading the `Blob` data to fail with a `DOMException` error.
3918+
* 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.
3919+
*
3920+
* @param path
3921+
* @param [options]
3922+
*
3923+
* @experimental
3924+
* @since v19.8.0
3925+
*/
3926+
export function openAsBlob(path: PathLike, options?: OpenAsBlobOptions): Promise<Blob>;
3927+
39033928
export interface OpenDirOptions {
39043929
/**
39053930
* @default 'utf8'

types/node/test/fs.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,23 @@ async function testPromisify() {
431431
fs.open('test', 'r', undefined, (err, fd) => {});
432432
}
433433

434+
{
435+
(async () => {
436+
// $ExpectType Blob
437+
const blob = await fs.openAsBlob('the.file.txt');
438+
});
439+
(async () => {
440+
// $ExpectType Blob
441+
const blob = await fs.openAsBlob('the.file.txt', {});
442+
});
443+
(async () => {
444+
// $ExpectType Blob
445+
const blob = await fs.openAsBlob('the.file.txt', {
446+
type: 'text/ecmascript',
447+
});
448+
});
449+
}
450+
434451
{
435452
fs.opendir('test', async (err, dir) => {
436453
const dirEnt: fs.Dirent | null = await dir.read();

types/node/ts4.8/fs.d.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3900,6 +3900,31 @@ declare module 'fs' {
39003900
* @return The number of bytes read.
39013901
*/
39023902
export function readvSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
3903+
3904+
export interface OpenAsBlobOptions {
3905+
/**
3906+
* An optional mime type for the blob.
3907+
*
3908+
* @default 'undefined'
3909+
*/
3910+
type?: string | undefined;
3911+
}
3912+
3913+
/**
3914+
* Returns a Blob whose data is backed by the given file.
3915+
*
3916+
* The file must not be modified after the `Blob` is created.
3917+
* Any modifications will cause reading the `Blob` data to fail with a `DOMException` error.
3918+
* 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.
3919+
*
3920+
* @param path
3921+
* @param [options]
3922+
*
3923+
* @experimental
3924+
* @since v19.8.0
3925+
*/
3926+
export function openAsBlob(path: PathLike, options?: OpenAsBlobOptions): Promise<Blob>;
3927+
39033928
export interface OpenDirOptions {
39043929
/**
39053930
* @default 'utf8'

types/node/ts4.8/test/fs.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,23 @@ async function testPromisify() {
431431
fs.open('test', 'r', undefined, (err, fd) => {});
432432
}
433433

434+
{
435+
(async () => {
436+
// $ExpectType Blob
437+
const blob = await fs.openAsBlob('the.file.txt');
438+
});
439+
(async () => {
440+
// $ExpectType Blob
441+
const blob = await fs.openAsBlob('the.file.txt', {});
442+
});
443+
(async () => {
444+
// $ExpectType Blob
445+
const blob = await fs.openAsBlob('the.file.txt', {
446+
type: 'text/ecmascript',
447+
});
448+
});
449+
}
450+
434451
{
435452
fs.opendir('test', async (err, dir) => {
436453
const dirEnt: fs.Dirent | null = await dir.read();

0 commit comments

Comments
 (0)