push-stream-std

@push-stream-std/push-stream-lzd (0.0.10)

Published 2026-07-21 15:52:21 +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-stream-lzd@0.0.10
"@push-stream-std/push-stream-lzd": "0.0.10"

About this package

@push-stream-std/push-stream-lzd

LZD+ dictionary compression and decompression as push-stream transforms.

Published as @push-stream-std/push-stream-lzd.

Synopsis

import { createDocumentCompressorTransform, createDocumentDecompressorTransform } from '@push-stream-std/push-stream-lzd';

const compressor = createDocumentCompressorTransform({ mode: 'stateful' });
const decompressor = createDocumentDecompressorTransform({ mode: 'stateful' });

source.pipe(compressor).pipe(sink);
compressedSource.pipe(decompressor).pipe(resultSink);
import { compressLzdPlus, decompressLzdPlus, createLzdPlusState } from '@push-stream-std/push-stream-lzd';

const state = createLzdPlusState();
const payload = compressLzdPlus('hello world', state);
const text = decompressLzdPlus(payload, state);
console.log(text); // 'hello world'

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-stream-lzd

Why

Provides LZD+ dictionary-based compression and decompression through a suffix trie with open-addressing hash maps. The codec layer offers both object-factor and binary encoding modes. The stream layer provides through transforms (createDocumentCompressorTransform / createDocumentDecompressorTransform) that operate on structured document frames, supporting both stateless (per-frame dictionary) and stateful (accumulated dictionary) modes with optional durability for checkpoint/restore.

API

Codec layer — @push-stream-std/push-stream-lzd

createLzdPlusState(dictionary)

Creates a fresh LZD+ compression state initialized with an optional dictionary of seed strings.

  • dictionary string[] (default []) – Initial dictionary entries for seeding the trie.
  • Returns A state object containing dictionaryStart, dictionaryLength, textStore, trie, and scratch.

compressLzdPlus(text, state, options)

Compresses text using the LZD+ codec, returning a factor-based payload.

  • text string – Text to compress.
  • state object – Compression state from createLzdPlusState.
  • options object (optional):
    • emitAdditions boolean (default true) – Include dictionary addition positions in the result.
  • Returns { encoding: 'lzd+', length, factors, additions }.

compressLzdPlusBinary(text, state, options)

Compresses text using the LZD+ codec, returning a binary Uint8Array payload.

  • text string – Text to compress.
  • state object – Compression state.
  • options object (optional):
    • emitAdditions boolean (default true) – Include dictionary addition positions.
  • Returns { encoding: 'lzd+', length, data: Uint8Array, additions }.

decompressLzdPlus(payload, state)

Decompresses a factor-based payload back to text.

  • payload object – Must have encoding: 'lzd+' and factors array.
  • state object – Decompression state (updated in place with new dictionary entries).
  • Returns string – The reconstructed text.

encodeLzdPlusPayload(payload)

Encodes a factor-based payload to a binary Uint8Array with the LZD+ wire format (magic header, version, length, factor count, factor body).

decodeLzdPlusPayload(bytes)

Decodes a binary Uint8Array in the LZD+ wire format back to a factor-based payload.

serializeLzdPlusState(state)

Serializes the current compression state's dictionary to a JSON-compatible snapshot.

  • Returns { dictionary: string[] }.

restoreLzdPlusState(snapshot)

Restores a compression state from a previously serialized snapshot.

  • snapshot { dictionary: string[] }.
  • Returns A fresh state object.

Stream layer

createDocumentCompressorTransform(options)

Creates a through stream that compresses textual content in structured document frames.

  • options object (optional):
    • mode 'stateless' | 'stateful' (default 'stateless') – Dictionary lifetime. Stateful accumulates across frames; stateless creates a new dictionary per frame.
    • durability object (optional) – If { enabled: true }, emits checkpoint
    • keepOriginal boolean (default false) – If true, preserves originalText in the frame.
    • includeDictionarySnapshot boolean (default false) – Includes the serialized dictionary in each compressed payload.
    • extractText (frame) => { text, locationKey } | null – Custom text extractor.
    • attachCompressed (frame, payload, info, options) => frame – Custom payload attacher.
  • Returns A through object with pipe(), write(), end(), resume(), abort(), paused, ended, source, sink.

createDocumentDecompressorTransform(options)

Creates a through stream that decompresses LZD+ content back to text in structured document frames.

  • options object (optional):
    • mode 'stateless' | 'stateful' (default 'stateless') – Dictionary lifetime.
    • durability object (optional) – If { enabled: true }, supports state restore via META frames.
    • extractCompressed (frame) => { payload, locationKey } | null – Custom compressed payload extractor.
    • attachText (frame, text, info) => frame – Custom text attacher.
  • Returns A through object with the same through stream interface.

Tests

npm test

Requirements

Node.js 22 or later. ESM only.

Dependencies

Development Dependencies

ID Version
lz4js ^0.2.0

Keywords

push-stream stream lz4 compress decompress
Details
npm
2026-07-21 15:52:21 +00:00
0
SEE LICENSE IN LICENSE
latest
9.5 KiB
Assets (1)
Versions (8) View all
0.0.10 2026-07-21
0.0.9 2026-07-21
0.0.8 2026-07-20
0.0.7 2026-07-20
0.0.6 2026-07-20