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-streams-ts

v1.0.3

Published

TypeScript-based Compression Streams API implementation using zlib, with support for deflate64 decompression.

Readme

Introduction

A high-performance TypeScript port of zlib, providing deflate and inflate compression algorithms with full compatibility to the original C library.

Features

  • Complete zlib API: Full implementation of deflate and inflate with all compression levels and strategies
  • Deflate64 Support: Extended deflate algorithm for larger windows (up to 64KB)
  • Web Streams API: Modern CompressionStream and DecompressionStream classes
  • Zero-copy streaming: Efficient buffer management for high-throughput applications
  • TypeScript: Fully typed with comprehensive type definitions
  • RFC Compliance: Implements RFC 1950 (zlib), RFC 1951 (deflate), and RFC 1952 (gzip)

Installation

npm install zlib-streams-ts

Usage

Web Streams API (Recommended)

import { CompressionStream, DecompressionStream } from 'zlib-streams-ts';

// Compression
const compressor = new CompressionStream('deflate');
const compressed = await new Response('Hello World').body
  .pipeThrough(compressor)
  .getReader()
  .read();

// Decompression
const decompressor = new DecompressionStream('inflate');
const decompressed = await new Response(compressed.value).body
  .pipeThrough(decompressor)
  .getReader()
  .read();

Low-level Stream API

import {
  createDeflateStream,
  deflateInit,
  deflate,
  deflateEnd,
  createInflateStream,
  inflateInit,
  inflate,
  inflateEnd
} from 'zlib-streams-ts';

// Compression
const deflateStream = createDeflateStream();
deflateInit(deflateStream, 6); // compression level 6

const input = new TextEncoder().encode('Hello World');
deflateStream.next_in = input;
deflateStream.avail_in = input.length;

const output = new Uint8Array(1024);
deflateStream.next_out = output;
deflateStream.avail_out = output.length;

deflate(deflateStream, Z_FINISH);
deflateEnd(deflateStream);

// Decompression
const inflateStream = createInflateStream();
inflateInit(inflateStream);

inflateStream.next_in = output;
inflateStream.avail_in = deflateStream.total_out;

const result = new Uint8Array(1024);
inflateStream.next_out = result;
inflateStream.avail_out = result.length;

inflate(inflateStream, Z_FINISH);
inflateEnd(inflateStream);

API Reference

CompressionStream

A Web Streams API TransformStream for compression.

new CompressionStream(format?: 'deflate' | 'gzip' | 'deflate-raw', options?: {
  level?: number;     // 0-9, default: 6
  strategy?: number;  // compression strategy
})

DecompressionStream

A Web Streams API TransformStream for decompression.

new DecompressionStream(format?: 'inflate' | 'gzip' | 'deflate-raw' | 'deflate64-raw')

Low-level Functions

Deflate

  • createDeflateStream() - Create a deflate stream
  • deflateInit(stream, level) - Initialize deflate stream
  • deflate(stream, flush) - Compress data
  • deflateEnd(stream) - Clean up deflate stream

Inflate

  • createInflateStream(deflate64?) - Create an inflate stream
  • inflateInit(stream) - Initialize inflate stream
  • inflate(stream, flush) - Decompress data
  • inflateEnd(stream) - Clean up inflate stream

Compression Levels

  • 0: No compression (stored)
  • 1-5: Fast compression with decreasing speed
  • 6: Default balance of speed/size
  • 7-9: Best compression with decreasing speed

Supported Formats

  • deflate: Raw deflate compressed data
  • gzip: Gzip wrapper with header and CRC
  • deflate-raw: Deflate without zlib wrapper
  • deflate64-raw: Extended raw deflate with 64KB window

Performance

This implementation is optimized for performance with:

  • Efficient bit manipulation
  • Zero-copy buffer management
  • Streaming architecture
  • Comprehensive test coverage

Testing

Run the test suite:

npm test

Run with coverage:

npm run coverage:c8

Building

npm run build:min  # Create minified build

License

This project is licensed under the MIT License. See LICENSE.md for details.

Acknowledgments

This is a TypeScript port of the original zlib C library by Jean-loup Gailly and Mark Adler.