Mpull
Bun

method

fs.promises.FileHandle.pull

...transforms: Transform[]

Return the file contents as an async iterable using the node:stream/iter pull model. Reads are performed in chunkSize-byte chunks (default 128 KB). If transforms are provided, they are applied via stream/iter pull().

The file handle is locked while the iterable is being consumed and unlocked when iteration completes, an error occurs, or the consumer breaks.

This function is only available when the --experimental-stream-iter flag is enabled.

import { open } from 'node:fs/promises';
import { text } from 'node:stream/iter';
import { compressGzip } from 'node:zlib/iter';

const fh = await open('input.txt', 'r');

// Read as text
console.log(await text(fh.pull({ autoClose: true })));

// Read 1 KB starting at byte 100
const fh2 = await open('input.txt', 'r');
console.log(await text(fh2.pull({ start: 100, limit: 1024, autoClose: true })));

// Read with compression
const fh3 = await open('input.txt', 'r');
const compressed = fh3.pull(compressGzip(), { autoClose: true });
...args: [...transforms: Transform[], options: PullOptions]

Referenced types