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

@httpx/compress

v0.3.12

Published

Compression utilities

Downloads

1,198

Readme

@httpx/compress

Lightweight compression helpers based on widely available Compression Streams API. Works in node, bun, edge, cloudflare and browsers. Provides support for string encoding (base64 and base64-urlsafe).

npm changelog codecov bundles node browserslist size downloads license

Install

$ npm install @httpx/compress
$ yarn add @httpx/compress
$ pnpm add @httpx/compress

Features

  • 👉  Compress and decompress strings or Uint8Array.
  • 🦄  Support base64 encoding for strings (and base64-urlsafe).
  • 📐  Lightweight (starts at ~570B)
  • 🛡️  Tested on node 20-25, browser, bun, cloudflare workers and runtime/edge.
  • 🙏  Works cross-realms (workers, browser, bun, edge, node, cloudflare...)
  • 🗝️  Available in ESM and CJS formats.

Documentation

👉 Official website or GitHub Readme

Quickstart

import { Compressor, Decompressor } from "@httpx/compress";

const compressor = new Compressor("gzip");
const gzippedStr = await compressor.toEncodedString("Hello, World! 🦆", {
  encoding: "base64", // optional, 'base64' by default
});

const decompressor = new Decompressor("gzip");
const originalStr = await decompressor.fromEncodedString(gzippedStr);

Api

Compressor

| Method | Description | | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | | toUint8Array() | Compress a string or a Uint8Array to a binary Uint8Array. | | toEncodedString() | Compress a string or a Uint8Array to a encoded string. |

Decompressor

| Method | Description | | --------------------- | ----------------------------------------------------------------- | | fromUint8Array() | Decompresses a compressed Uint8Array to its original binary form. | | fromEncodedString() | Compress a string or a Uint8Array to a encoded string. |

Usage

Compressor

toUint8Array

import { Compressor } from "@httpx/compress";

const compressor = new Compressor("gzip"); // or 'deflate'
const longString = "Hello, World! 🦆".repeat(500_000);
const compressedUInt8 = await compressor.toUint8Array(longString);

toEncodedString

import { Compressor } from "@httpx/compress";

const compressor = new Compressor("gzip"); // or 'deflate'
const longString = "Hello, World! 🦆".repeat(500_000);
const compressedString = await compressor.toEncodedString(longString, {
  // Optional.
  // Supported values: 'base64' (default), 'base64_urlsafe'
  encoding: "base64",
});

Decompressor

fromUint8Array

import { Decompressor } from "@httpx/compress";

const decompressor = new Decompressor("gzip"); // or 'deflate'
const decompressedUInt8 = await decompressor.fromUint8Array(compressedUInt8);

fromEncodedString

import { Decompressor } from "@httpx/compress";

const decompressor = new Decompressor("gzip"); // or 'deflate'
const decompressedString =
  await decompressor.fromEncodedString(compressedString);

Benchmarks

Performance is continuously monitored thanks to codspeed.io.

CodSpeed Badge

 RUN  v4.1.0 /home/sebastien/github/httpx/packages/compress


 ✓ bench/compress-string.bench.ts > Compressor 3372ms
     name                                                                               hz      min      max     mean      p75      p99     p995     p999      rme  samples
   · Compressor('gzip').toEncodedString/base64 (original size: 10 MB)              14.6228  51.2665   105.03  68.3865  62.2349   105.03   105.03   105.03  ±21.33%        8
   · Compressor('gzip').toEncodedString/base64_urlsafe (original size: 10 MB)      17.4693  51.7026  76.1508  57.2432  53.6072  76.1508  76.1508  76.1508  ±12.73%        9
   · Compressor('deflate').toEncodedString/base64 (original size: 10 MB)           17.9078  50.0100  64.0214  55.8416  56.9880  64.0214  64.0214  64.0214   ±7.29%        9
   · Compressor('deflate').toEncodedString/base64-url_safe (original size: 10 MB)  18.4466  47.9274  77.2346  54.2105  56.3455  77.2346  77.2346  77.2346  ±11.81%       10

 ✓ bench/decompress-string.bench.ts > Decompressor 2353ms
     name                                                                                     hz     min     max    mean     p75     p99    p995    p999      rme  samples
   · Decompressor('gzip').fromEncodedString (compressed size: 40.5 kB / total: 10 MB)     7.9639  113.95  146.56  125.57  127.04  146.56  146.56  146.56  ±19.29%        4
   · Decompressor('deflate').fromEncodedString (compressed size: 40.5 kB / total: 10 MB)  7.7943  120.79  135.43  128.30  130.74  135.43  135.43  135.43   ±7.76%        4

 ✓ bench/decompress-uint8array.bench.ts > Decompressor 2439ms
     name                                                                                  hz      min     max    mean     p75     p99    p995    p999      rme  samples
   · Decompressor('gzip').fromUint8Array (compressed size: 30.4 kB / total: 10 MB)     7.4025   108.34  183.06  135.09  135.23  183.06  183.06  183.06  ±40.07%        4
   · Decompressor('deflate').fromUint8Array (compressed size: 30.4 kB / total: 10 MB)  9.2430  92.0323  124.78  108.19  116.49  124.78  124.78  124.78  ±14.55%        5

 ✓ bench/compress-uint8array.bench.ts > Compressor 1663ms
     name                                                            hz      min      max     mean      p75      p99     p995     p999      rme  samples
   · Compressor('gzip').toUint8Array (original size: 10 MB)     15.7262  54.1742  81.3818  63.5881  60.8143  81.3818  81.3818  81.3818  ±12.71%        8
   · Compressor('deflate').toUint8Array (original size: 10 MB)  18.2422  47.6582  68.4186  54.8180  60.0257  68.4186  68.4186  68.4186  ±10.48%       10

 BENCH  Summary

  Compressor('deflate').toEncodedString/base64-url_safe (original size: 10 MB) - bench/compress-string.bench.ts > Compressor
    1.03x faster than Compressor('deflate').toEncodedString/base64 (original size: 10 MB)
    1.06x faster than Compressor('gzip').toEncodedString/base64_urlsafe (original size: 10 MB)
    1.26x faster than Compressor('gzip').toEncodedString/base64 (original size: 10 MB)

  Compressor('deflate').toUint8Array (original size: 10 MB) - bench/compress-uint8array.bench.ts > Compressor
    1.16x faster than Compressor('gzip').toUint8Array (original size: 10 MB)

  Decompressor('gzip').fromEncodedString (compressed size: 40.5 kB / total: 10 MB) - bench/decompress-string.bench.ts > Decompressor
    1.02x faster than Decompressor('deflate').fromEncodedString (compressed size: 40.5 kB / total: 10 MB)

  Decompressor('deflate').fromUint8Array (compressed size: 30.4 kB / total: 10 MB) - bench/decompress-uint8array.bench.ts > Decompressor
    1.25x faster than Decompressor('gzip').fromUint8Array (compressed size: 30.4 kB / total: 10 MB)

See benchmark file for details.

Bundle size

Bundle size is tracked by a size-limit configuration

| Scenario (esm) | Size (compressed) | | ------------------------------------- | ----------------: | | import { Compressor } | ~ 568B | | import { Decompressor } | ~ 450B | | import { Decompressor, Compressor } | ~ 697B |

For CJS usage (not recommended) track the size on bundlephobia.

Compatibility

| Level | CI | Description | | ------------ | --- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Node | ✅ | CI for 20.x, 22.x, 24.x & 25.x. | | Browser | ✅ | Tested with latest chrome (vitest/playwright) | | Browserslist | ✅ | > 95% on 01/2025. defaults, chrome >= 96, firefox >= 105, edge >= 113, safari >= 15, ios >= 15, opera >= 103, not dead | | Bun | ✅ | Tested with latest (at time of writing >= 1.3.3) | | Edge | ✅ | Ensured on CI with @vercel/edge-runtime. | | Cloudflare | ✅ | Ensured with @cloudflare/vitest-pool-workers (see wrangler.toml | | Typescript | ✅ | TS 5.4 + / are-the-type-wrong checks on CI. | | ES2022 | ✅ | Dist files checked with es-check | | Performance | ✅ | Monitored with codspeed.io |

For older browsers: most frontend frameworks can transpile the library (ie: nextjs...)

Contributors

Contributions are welcome. Have a look to the CONTRIBUTING document.

Sponsors

If my OSS work brightens your day, let's take it to new heights together! Sponsor, coffee, or star – any gesture of support fuels my passion to improve. Thanks for being awesome! 🙏❤️

Special thanks to

License

MIT © Sébastien Vanvelthem and contributors.