npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@addmaple/lz4

v0.2.0

Published

Fast lz4 compression in the browser using Rust + WASM

Readme

@addmaple/lz4

Fast LZ4 compression in the browser and Node.js using Rust + WASM.

2.5x-3.5x faster than lz4js.

Implementation (Rust)

This package is backed by these Rust crates in the wasm-fast-compress repo:

  • codec-lz4 (this repo): high-level codec wrapper
  • lz4_flex (Git fork, branch wasm-simd): core LZ4 implementation with WASM SIMD128 hot paths

SIMD acceleration (how it works)

  • We build two WASM binaries:
    • lz4.base.wasm: compiled without +simd128
    • lz4.simd.wasm: compiled with -C target-feature=+simd128
  • At runtime, the JS loader detects SIMD support and loads the best binary automatically.

On wasm32, the SIMD build benefits from:

  • lz4_flex explicit wasm32 + simd128 intrinsics for match finding / copying hot paths
  • additional LLVM autovectorization where applicable

Installation

npm install @addmaple/lz4

Usage

import { init, compress } from '@addmaple/lz4';

// Optional: call init() to avoid first-call latency.
// If you skip init(), the first compress/decompress call will lazy-initialize.
await init();

const input = new TextEncoder().encode('hello world');
const compressed = await compress(input);

Lazy init (init() optional)

import { compress } from '@addmaple/lz4';

const input = new TextEncoder().encode('hello world');
const compressed = await compress(input); // triggers lazy init on first call

Streaming compression + decompression

For chunked input (e.g. streaming over the network), use the handle-based streaming helpers:

import { init, StreamingCompressor, StreamingDecompressor } from '@addmaple/lz4';

// Optional: init() is not required; streaming helpers also lazy-init.
await init();

// Compress
const enc = new StreamingCompressor();
const c1 = await enc.compressChunk(chunk1, false);
const c2 = await enc.compressChunk(chunk2, false);
const c3 = await enc.compressChunk(chunk3, true); // finish

// Decompress (finish must be true to produce output for frame format)
const dec = new StreamingDecompressor();
await dec.decompressChunk(c1, false);
await dec.decompressChunk(c2, false);
const plain = await dec.decompressChunk(c3, true);

Streaming to fetch() (ergonomic)

If you want to upload a File/Blob with LZ4 compression, you can pipe it through the built-in stream helper:

import { createCompressionStream } from '@addmaple/lz4';

const body = file.stream().pipeThrough(createCompressionStream());

await fetch('/upload', {
  method: 'POST',
  headers: {
    // Not a standard encoding token like gzip; your server must explicitly support this.
    'Content-Encoding': 'lz4',
  },
  body,
  // Needed for streaming request bodies in some runtimes (notably Node fetch).
  duplex: 'half',
});

Streaming decompression from fetch() (ergonomic)

import { createDecompressionStream } from '@addmaple/lz4';

const res = await fetch('/download');
if (!res.body) throw new Error('No response body');

const decompressed = res.body.pipeThrough(createDecompressionStream());

// Example: read it all (or pipe somewhere else)
const buf = await new Response(decompressed).arrayBuffer();

Inline (Zero-latency)

WASM bytes embedded directly in JS — no separate file fetching:

import { init, compress } from '@addmaple/lz4/inline';

await init();
const compressed = await compress(input);

API

init()

Initialize the WASM module.

compress(input)

  • input: Uint8Array
  • Returns: Promise<Uint8Array>

Note: LZ4 is a single-speed algorithm optimized for maximum throughput. Unlike Brotli/Gzip, it doesn't have compression levels.

Sponsor

Development of this module was sponsored by addmaple.com — a modern data analysis platform.

License

MIT