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

kafka-lz4-lite

v2.0.0

Published

Fast, pure JS Kafka LZ4 codec for kafkajs (powered by lz4-lite), with zero native build step

Downloads

137,151

Readme

Kafka LZ4 Lite

A fast, lightweight, pure-JS LZ4 codec for kafkajs — compression and decompression of Kafka payloads with zero native build step.

Why Kafka LZ4 Lite

  • Pure JavaScript, zero native dependencies. No node-gyp, no prebuilt binaries, no toolchain — it installs and runs anywhere Node does, including slim/Alpine and serverless images.
  • Fast. Now powered by lz4-lite, a clean, spec-compliant LZ4 reimplementation, decode throughput is on par with native C++/Rust and WASM codecs (see Performance).
  • Small, predictable memory footprint. Unlike native bindings — which allocate a full LZ4 block buffer per call — and WASM codecs, which reserve a large fixed linear heap, this codec keeps a low, steady memory profile, so it stays comfortably inside tight container/pod limits.
  • Fully typed. All exported functions and objects ship with TypeScript declarations.
  • Spec-compliant frames. Interoperable with liblz4/lz4 and other compliant LZ4 codecs — frames it produces are decoded by them, and vice-versa.

Performance

kafka-lz4-lite recently migrated its underlying codec from lz4js to lz4-lite. The upgrade is a major step up while keeping the same simple API:

| metric (kafkajs consuming 200k LZ4 messages) | before (lz4js) | now (lz4-lite) | improvement | | -------------------------------------------- | ---------------- | ---------------- | ----------- | | decode time | 1312 ms | 92 ms | ~14× faster | | end-to-end consume | 1526 ms | 280 ms | ~5× faster | | peak memory | 660 MB | 432 MB | ~35% lower |

Measured on Node 20 (Apple M1 Max) decoding ~206 MB of realistic JSON events; your numbers will vary with hardware, payload, and batch size. Decode speed now lands in the same range as native and WASM codecs — without any binary artifact.

Usage

Register the codec once during application startup; it then applies to all kafkajs producers and consumers globally:

import { CompressionTypes, CompressionCodecs } from "kafkajs";
import { codec } from "kafka-lz4-lite";

CompressionCodecs[CompressionTypes.LZ4] = codec;

Worker-thread variant (optional)

The library also offers a worker-pool codec built on Piscina, which offloads compression and decompression to worker threads:

import { CompressionTypes, CompressionCodecs } from "kafkajs";
import { createCodec } from "kafka-lz4-lite/worker";

const codec = createCodec(); // accepts the same options as new Piscina()
// e.g. createCodec({ minThreads: 2, maxThreads: 4 })
// The 'filename' option is ignored — the worker file is provided internally.

CompressionCodecs[CompressionTypes.LZ4] = codec;

Because kafkajs invokes the codec once per record batch (not per message), decode work is already well amortized, and the synchronous codec above is usually the faster choice — moving each batch across the worker-thread boundary adds copy/serialization overhead. Reach for the worker variant only for unusually large payloads, and benchmark your own workload before adopting it.

Requirements

Node.js >= 16.0.0