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

zlib-sync-rust

v1.0.1

Published

Sync zlib stream inflater for Node.js, built with Rust

Readme

zlib-sync-rust

NPM Version
NPM Downloads

High-performance sync Zlib inflater for Node.js, built with Rust (napi-rs).

A simple, fast, and synchronous zlib-stream decoder, designed for use cases like Discord Gateway compression, or any application needing zlib-stream inflation without async streams or event handling.


🚀 Features

  • Synchronous interface – No on('data') handling
  • Streaming decompression – Keeps state across push() calls
  • Auto stream-reset on end – Works well for multiple stream chunks (e.g. Discord)
  • Rust + napi-rs – Fast, portable, and memory-safe
  • ✅ Supports both CommonJS and ESM
  • ✅ Same usage style as zlib-sync but written in Rust
  • Prebuilt binaries for major platforms – No need to compile or install build tools

📦 Install

npm install zlib-sync-rust

🔧 Usage

Basic Example

CJS

const { Inflater } = require('zlib-sync-rust');

const inflater = new Inflater();

// Push compressed data chunk by chunk (zlib-stream)
const out1 = inflater.push(chunk1);
const out2 = inflater.push(chunk2);
const out3 = inflater.push(chunk3);
const result = Buffer.concat([out1, out2, out3]);
console.log(result.toString());

ESM

import { Inflater } from 'zlib-sync-rust';

const inflater = new Inflater();

const out = inflater.push(zlibStreamChunk);
console.log(out.toString());

🔍 API

new Inflater()

Creates a new zlib-stream inflater instance.


inflater.push(input: Buffer, flush?: boolean): Buffer

| Parameter | Type | Default | Description | | --------- | --------- | -------- | -------------------------------------- | | input | Buffer | Required | The compressed zlib stream chunk | | flush | boolean | false | Whether to finalize the current stream |

  • If flush is false (default), it keeps streaming.
  • If flush is true, it signals the end of a zlib stream.
  • When a stream ends (via flush: true or stream end marker), internal state is auto-reset for the next stream.

inflater.reset(): void

Manually reset the internal inflater state. This is optional in most use cases, but may be useful when:

  • You detect the end of a zlib stream manually (e.g. Discord's 0x00 00 ff ff marker)
  • You want to force discard current stream state between data chunks
inflater.reset(); // Ready for a new zlib stream

⚠️ Streaming Strategy Notes

  • This inflater supports both:

    • Single continuous zlib streams (e.g. a file split into parts)
    • Multiple independent zlib streams (e.g. Discord's message framing)
  • When used with Discord Gateway:

    • Discord sends separate zlib streams, each ending with 0x00 00 ff ff
    • You should call .reset() after detecting this marker
    • Do not call with flush: true unless you know the entire stream is present

⚡ Why?

Node's native zlib is event-based and not friendly for some low-level protocols like Discord's zlib-stream compression. This library gives you a sync-friendly, stateful inflater with Rust-level performance.


🚀 Prebuilt binaries

zlib-sync-rust provides prebuilt .node binaries for major platforms:

  • Windows
  • Linux

No need for node-gyp or build tools. Install and use directly.

This uses @napi-build/cli.


🧰 License

MIT © 2025 Yuki