push-stream-std

@push-stream-std/push-write-file (0.0.9)

Published 2026-07-20 21:40:07 +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-write-file@0.0.9
"@push-stream-std/push-write-file": "0.0.9"

About this package

@push-stream-std/push-write-file

Write a push-stream to a file on disk.

Published as @push-stream-std/push-write-file.

Synopsis

import writeFile from '@push-stream-std/push-write-file';
import pushable from '@push-stream-std/push-pushable';

const source = pushable();
const sink = writeFile('/tmp/output.txt', { encoding: 'utf8', flags: 'w' });

source.pipe(sink);

source.push('hello\n');
source.push('world\n');
source.end();
// File /tmp/output.txt contains: hello\nworld\n

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-write-file

Why

A push-stream sink that writes each incoming value to a file via fs.write. The file is opened synchronously on creation so write errors during the first write() call are caught early. Values are converted to strings using the specified encoding and written asynchronously, with backpressure signaling via the push-stream pause/resume protocol. Pending writes are queued with amortized O(1) via a head pointer pattern.

API

writeFile(path, options)

Creates a file-writing sink stream.

  • path string – File path to write to.
  • options object (optional):
    • encoding string (default 'utf8') – Character encoding for string conversion.
    • flags string (default 'w') – File system flags passed to fs.openSync.
    • mode number (default 0o666) – File permission mode.
  • Returns A sink stream with pipe(), write(), end(), abort(), paused, and ended. The pipe() method accepts a source stream.

Tests

npm test

Tests cover writing values to a file, encoding options, file open errors, write error handling, end-with-remaining-writes, and abort cleanup with file close.

Requirements

Node.js 22 or later. ESM only.

Dependencies

Dependencies

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

Keywords

push-stream stream file fs write
Details
npm
2026-07-20 21:40:07 +00:00
0
SEE LICENSE IN LICENSE
3.5 KiB
Assets (1)
Versions (6) View all
0.0.10 2026-07-21
0.0.9 2026-07-20
0.0.8 2026-07-20
0.0.7 2026-07-19
0.0.5 2026-07-19