push-stream-std

@push-stream-std/push-utf8-decoder (0.0.3)

Published 2026-07-19 21:14: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-utf8-decoder@0.0.3
"@push-stream-std/push-utf8-decoder": "0.0.3"

About this package

push-utf8-decoder

Decode a buffer stream to UTF-8 strings, handling multi-byte characters split across chunks.

Published as @push-stream-std/push-utf8-decoder.

Synopsis

import utf8Decoder from '@push-stream-std/push-utf8-decoder';

const decoder = utf8Decoder({ stripBOM: true, replaceInvalid: true });

const sink = {
  paused: false,
  write(v) { console.log(v); },
  end() { console.log('done'); }
};

// Pipe a buffer-producing source through the decoder to the sink
source.pipe(decoder).pipe(sink);

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-utf8-decoder

Description

A through stream that decodes incoming Buffer or ArrayBuffer chunks into JavaScript strings. Multi-byte UTF-8 characters split across chunk boundaries are handled correctly by buffering incomplete byte sequences. String inputs are passed through directly. On end, any remaining buffered bytes are decoded and flushed before closing the downstream sink.

API

utf8Decoder(options)

Creates a UTF-8 decoding through stream.

  • options object (optional):
    • stripBOM boolean (default true) – Strip the BOM (\uFEFF) from the first chunk if present.
    • replaceInvalid boolean (default true) – Replace invalid byte sequences with the Unicode replacement character (\uFFFD). When false, invalid sequences cause an error.
  • Returns A through stream with pipe(), write(), end(), abort(), resume(), paused, and ended.

Tests

npm test

Tests cover ASCII passthrough, multi-byte character decoding, split multi-byte codepoints across chunks, BOM stripping, invalid byte replacement, string input passthrough, and abort cleanup.

Requirements

Node.js 18 or later. ESM only.

License

MIT

Keywords

push-stream stream utf8 decoder unicode
Details
npm
2026-07-19 21:14:30 +00:00
0
SEE LICENSE IN LICENSE
3.7 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