@push-stream-std/push-file (0.0.6)
Installation
@push-stream-std:registry=https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/npm install @push-stream-std/push-file@0.0.6"@push-stream-std/push-file": "0.0.6"About this package
push-file
Read file as a push-stream source.
Published as @push-stream-std/push-file.
Synopsis
import file from '@push-stream-std/push-file';
file('/path/to/data.txt', { encoding: 'utf8', bufferSize: 4096 }).pipe({
write(data) { process.stdout.write(data); },
end(err) { if (err) console.error(err); },
abort(err) { console.error('aborted:', err); },
paused: false
});
Install
npm config set @push-stream-std:registry https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/
npm config set -- //hub.kl1.tenere.ai/api/packages/push-stream-std/npm/:_authToken "$PACKAGE_TOKEN"
npm install @push-stream-std/push-file
Description
Reads a file from disk and streams its content as Buffer chunks (or decoded strings if encoding is set). Supports byte range reads via start and end options. Files are opened asynchronously via fs/promises but reads use the callback-based fs.read to integrate with push-stream's callback-oriented resume pattern. Aborting the source closes the file descriptor and ends the stream.
API
file(path, options)
path-string- Path to the file to read.options.encoding-string | null(default:null) - If set, chunks are decoded to strings (e.g.'utf8').options.start-number(default:0) - Byte position to start reading from.options.end-number(default:Infinity) - Byte position to stop reading at (inclusive).options.bufferSize-number(default:16384) - Size of each read buffer in bytes.options.flags-string(default:'r') - File system flags forfs.open.
Returns a push-stream source. Pipe it to a sink to receive file content chunks. Call source.abort(err) to close the file descriptor and end the stream.
Tests
npm test
Tests cover reading file content, encoding support, byte range reads (start/end), backpressure with resume, abort on error (nonexistent file), and proper end signaling when file is fully read.
Requirements
Node.js 18 or later. ESM only.
License
MIT
Dependencies
Dependencies
| ID | Version |
|---|---|
| @push-stream-std/push-stream-base | * |