@push-stream-std/push-utf8-decoder (0.0.5)
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.5"@push-stream-std/push-utf8-decoder": "0.0.5"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(defaulttrue) – Strip the BOM (\uFEFF) from the first chunk if present. - replaceInvalid
boolean(defaulttrue) – Replace invalid byte sequences with the Unicode replacement character (\uFFFD). Whenfalse, invalid sequences cause an error.
- stripBOM
- Returns A through stream with
pipe(),write(),end(),abort(),resume(),paused, andended.
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