@push-stream-std/push-write-file (0.0.7)
Published 2026-07-19 23:32:27 +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.7"@push-stream-std/push-write-file": "0.0.7"About this package
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
Description
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 tofs.openSync. - mode
number(default0o666) – File permission mode.
- encoding
- Returns A sink stream with
pipe(),write(),end(),abort(),paused, andended. Thepipe()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 18 or later. ESM only.
License
MIT
Dependencies
Dependencies
| ID | Version |
|---|---|
| @push-stream-std/push-stream-base | * |
Keywords
push-stream
stream
file
fs
write