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

@culvert/gzip

v0.1.0

Published

Streaming gzip compression and decompression. Platform-native DEFLATE. CRC-32 verified. Concatenated member support.

Downloads

64

Readme

@culvert/gzip

Streaming gzip compression and decompression. Platform DEFLATE. CRC-32 verified. Zero dependencies beyond Culvert.

await pipe(source, gzip(), writeTo("output.gz"));
await pipe(readFile("output.gz"), gunzip(), writeTo("output"));

Install

npm install @culvert/gzip

Compress

import { gzip } from "@culvert/gzip";
import { pipe } from "@culvert/stream";

await pipe(source, gzip(), writeTo("data.json.gz"));

With options:

await pipe(
  source,
  gzip({
    filename: "data.json", // stored in gzip header (FNAME)
    mtime: new Date(), // stored in gzip header; defaults to epoch
    comment: "nightly export", // stored in gzip header (FCOMMENT)
    signal: AbortSignal.timeout(5000),
  }),
  writeTo("data.json.gz"),
);

mtime defaults to Unix epoch (new Date(0)) for reproducible output. Two compressions of the same input with the same options produce byte-identical gzip output.

Decompress

import { gunzip } from "@culvert/gzip";

await pipe(readFile("data.json.gz"), gunzip(), writeTo("data.json"));

With abort:

await pipe(compressedSource, gunzip({ signal }), writeTo("output"));

Compose with tar

The reason this package exists:

import { createTar, EPOCH } from "@culvert/tar";
import { gzip } from "@culvert/gzip";

await pipe(
  createTar(async (tar) => {
    await tar.addFile({
      name: "report.csv",
      source,
      size,
      lastModified: EPOCH,
    });
  }),
  gzip(),
  writeTo("archive.tar.gz"),
);

HTTP response compression

import { gzip } from "@culvert/gzip";
import { pipe, toReadableStream } from "@culvert/stream";

const body = pipe(generateResponse(), gzip());
return new Response(toReadableStream(body), {
  headers: { "Content-Encoding": "gzip" },
});

BYOC (bring your own compressor)

The platform's CompressionStream handles DEFLATE. If you need a custom codec — different compression level, a pure-JS implementation, or a WebAssembly engine — use the escape hatch:

import { gzipWith, gunzipWith } from "@culvert/gzip";

await pipe(
  source,
  gzipWith({ compress: myDeflateTransform }),
  writeTo("out.gz"),
);
await pipe(
  readFile("out.gz"),
  gunzipWith({ decompress: myInflateTransform }),
  writeTo("out"),
);

Your custom transform handles raw DEFLATE (RFC 1951). @culvert/gzip handles the gzip framing, CRC-32, and ISIZE around it.

Errors

Two error classes, same taxonomy as @culvert/zip and @culvert/tar:

import { GzipCorruptionError, GzipAbortError } from "@culvert/gzip";

try {
  await pipe(source, gunzip(), collect());
} catch (err) {
  if (err instanceof GzipCorruptionError) {
    // bad magic, bad CRC, truncated stream, invalid DEFLATE
  }
  if (err instanceof GzipAbortError) {
    // AbortSignal fired
  }
}

CRC-32 and ISIZE are validated by the platform. Mismatches throw GzipCorruptionError.

Limitations

Single gzip member only. RFC 1952 allows concatenated gzip members (cat a.gz b.gz > combined.gz), but the WHATWG Compression Streams spec defines a gzip stream as exactly one member. DecompressionStream does not report how many compressed bytes it consumed, so detecting member boundaries is impossible without owning the DEFLATE implementation. Some runtimes (Node.js) handle concatenated members as a non-spec extension, but this isn't portable across browsers, Cloudflare Workers, Deno, and Bun.

If you need concatenated member support, use gunzipWith() with a custom DEFLATE decompressor that tracks consumed byte counts.

No compression level control. CompressionStream doesn't accept a level parameter. The platform picks its default (typically zlib level 6). For level control today, use gzipWith() with a custom DEFLATE transform that accepts level configuration.

No permissive CRC mode. The platform always validates CRC-32. Its error behavior on mismatch is inconsistent across payload sizes and runtimes — sometimes it throws before yielding any data, sometimes after yielding all of it. We normalize to GzipCorruptionError. For damaged streams, use gunzipWith() with a custom decompressor that skips validation.

API surface

gzip(options?)    → Transform<Uint8Array, Uint8Array>
gunzip(options?)  → Transform<Uint8Array, Uint8Array>
gzipWith(options) → Transform<Uint8Array, Uint8Array>
gunzipWith(options) → Transform<Uint8Array, Uint8Array>

GzipCorruptionError
GzipAbortError

Six runtime exports. Four type exports (GzipOptions, GunzipOptions, GzipWithOptions, GunzipWithOptions). That's the whole package.

How it works

The compressor uses CompressionStream("deflate-raw") for raw DEFLATE and wraps it in gzip framing (RFC 1952) with a CRC-32 footer computed by @culvert/crc32. This gives us control over header fields (FNAME, FCOMMENT, MTIME) and reproducible output.

The decompressor uses DecompressionStream("gzip") directly. The platform handles header parsing, DEFLATE, CRC-32, and ISIZE. We bridge async iterables to/from the Web Stream and normalize errors to GzipCorruptionError.

Related packages

stream
├── crc32   (leaf — no culvert deps)
├── zip     (stream + crc32)
├── tar     (stream)
└── gzip    ← you are here  (stream + crc32)

License

MIT. See LICENSE.