push-stream-std

@push-stream-std/push-file (0.0.8)

Published 2026-07-21 03:58:30 +00:00 by Dvorak

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.8
"@push-stream-std/push-file": "0.0.8"

About this package

@push-stream-std/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

Why

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 for fs.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 22 or later. ESM only.

Dependencies

Dependencies

ID Version
@push-stream-std/push-stream-base *

Keywords

push-stream stream file fs
Details
npm
2026-07-21 03:58:30 +00:00
0
SEE LICENSE IN LICENSE
latest
4.0 KiB
Assets (1)
Versions (5) View all
0.0.8 2026-07-21
0.0.7 2026-07-20
0.0.6 2026-07-20
0.0.5 2026-07-19
0.0.3 2026-07-19