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

@foodshare/compression-wasm

v1.3.1

Published

Response compression utilities with Brotli support - WebAssembly build

Readme

@foodshare/compression-wasm

Response compression utilities with Brotli support compiled to WebAssembly from Rust.

npm version License: MIT

Features

  • Brotli Compression - Better compression ratios than Gzip (not available in Deno!)
  • Gzip/Deflate - Standard compression formats
  • ETag Generation - SHA-256 based ETags for caching
  • Auto Algorithm - Automatic compression selection based on payload size
  • TypeScript Support - Full type definitions included

Why This Package?

Deno's CompressionStream doesn't support Brotli! This package brings Brotli compression to Supabase Edge Functions and other Deno runtimes via WebAssembly.

Installation

npm install @foodshare/compression-wasm
# or
yarn add @foodshare/compression-wasm
# or
pnpm add @foodshare/compression-wasm

Usage

Initialization

import init, { brotli_compress, gzip_compress } from '@foodshare/compression-wasm';

// Initialize WASM module (required once)
await init();

Brotli Compression

import init, { brotli_compress, brotli_decompress } from '@foodshare/compression-wasm';

await init();

const data = new TextEncoder().encode('Hello World!'.repeat(100));

// Compress with quality 4 (0-11, higher = better compression)
const compressed = brotli_compress(data, 4);
console.log(`Compressed: ${data.length} -> ${compressed.length} bytes`);

// Decompress
const decompressed = brotli_decompress(compressed);
const text = new TextDecoder().decode(decompressed);

Gzip Compression

import init, { gzip_compress, gzip_decompress } from '@foodshare/compression-wasm';

await init();

const data = new TextEncoder().encode('Hello World!');

// Compress with level 6 (0-9)
const compressed = gzip_compress(data, 6);

// Decompress
const decompressed = gzip_decompress(compressed);

Auto Compression

import init, { compress_auto } from '@foodshare/compression-wasm';

await init();

// Automatically selects:
// - Brotli for payloads > 1KB
// - Gzip for smaller payloads
const compressed = compress_auto(data);

ETag Generation

import init, { generate_etag } from '@foodshare/compression-wasm';

await init();

const data = new TextEncoder().encode('response body');
const etag = generate_etag(data);
// Returns: "a1b2c3..." (SHA-256 hash)

API Reference

brotli_compress(data, quality): Uint8Array

Compress data using Brotli. Quality: 0-11 (higher = better compression, slower).

brotli_decompress(data): Uint8Array

Decompress Brotli data.

gzip_compress(data, level): Uint8Array

Compress data using Gzip. Level: 0-9.

gzip_decompress(data): Uint8Array

Decompress Gzip data.

compress_auto(data): Uint8Array

Auto-select compression based on size (Brotli > 1KB, else Gzip).

generate_etag(data): string

Generate SHA-256 based ETag for caching.

Supabase Edge Function Example

import { serve } from 'https://deno.land/[email protected]/http/server.ts';
import init, { brotli_compress, generate_etag } from '@foodshare/compression-wasm';

await init();

serve(async (req) => {
  const data = JSON.stringify({ message: 'Hello from Edge!' });
  const body = new TextEncoder().encode(data);

  // Check if client accepts Brotli
  const acceptEncoding = req.headers.get('accept-encoding') || '';

  if (acceptEncoding.includes('br')) {
    const compressed = brotli_compress(body, 4);
    return new Response(compressed, {
      headers: {
        'Content-Type': 'application/json',
        'Content-Encoding': 'br',
        'ETag': generate_etag(body),
      },
    });
  }

  return new Response(body, {
    headers: { 'Content-Type': 'application/json' },
  });
});

Compression Comparison

| Algorithm | Ratio | Speed | Browser Support | |-----------|-------|-------|-----------------| | Brotli | Best | Slower | All modern | | Gzip | Good | Fast | Universal | | Deflate | Good | Fast | Universal |

Performance

  • Brotli compression ~100KB in ~200µs
  • Gzip compression ~100KB in ~100µs
  • Zero-copy operations with WASM

Browser Support

Works in all modern browsers with WebAssembly support:

  • Chrome 57+
  • Firefox 52+
  • Safari 11+
  • Edge 16+

License

MIT License - see LICENSE for details.

Related