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 🙏

© 2024 – Pkg Stats / Ryan Hefner

hono-compress

v0.6.0

Published

Compression plugin for Hono working with Bun

Downloads

269

Readme

hono-compress

Compression plugin for Hono

Drop-in replacement of the built-in Compress Middleware, but with some extra...

Features

  • all available compression formats (zstd, brotli, gzip, deflate)
  • ultra-fast and 100% type-safe
  • best format auto-selection
  • streaming response support
  • configurable compression level and zlib options
  • double-compressed content protection
  • content size threshold and custom filtering
  • Cloudflare Workers and Deno Deploy runtime detection
  • works with Node, Deno and Bun

Installation

npm install hono-compress
yarn add hono-compress
pnpm add hono-compress
bun add hono-compress
deno add hono-compress

Usage

import { Hono } from 'hono'
import { compress } from 'hono-compress'

const app = new Hono()

app.use(compress())

Configuration

compress({
  encoding,
  encodings,
  force,
  threshold,
  zstdLevel,
  brotliLevel,
  zlibLevel,
  options,
  filter,
})

encoding

Defaults to undefined.

The compression format encoding to use to compress the response content. Can be one of the following:

  • zstd
  • br
  • gzip
  • deflate

If not defined, all the formats declared in the option encodings are allowed.

This option is provided primarily to maintain compatibility with hono/compress; it is recommended to use the option encodings to set the wanted compression formats.

encodings

Defaults to ['zstd', 'br', 'gzip', 'deflate'].

The compression format encodings allowed to be used to compress the response content.

The first format matching the request accept-encoding is chosen to be used to compress the response content.

force

Defaults to false.

Forces content compression even if the request accept-encoding or the response content-type cannot be determined.

Use with caution.

threshold

Defaults to 1024.

The minimum size in bytes for a response content to be compressed.

zstdLevel

Defaults to 2.

Zstandard algorithm compression level (encoding zstd).

Refer to the zstd manual for more details.

brotliLevel

Defaults to 4.

Brotli algorithm compression level (encoding br).

Refer to the Brotli specification for more details.

zlibLevel

Defaults to 6.

Zlib algorithms compression level (encoding gzip and deflate).

Refer to the zlib manual for more details.

options

Defaults to {}.

Options passed to the node compression engine to compress content.

Refer to the node zlib documentation for more details.

filter

Defaults to undefined.

An optional function callback to state if the response content should be compressed or not.

Parameters

Return value

Boolean

By default, content compression is disabled on Cloudflare Workers and Deno Deploy, a custom filter can be used to bypass this behavior and force the response to be always compressed:

import type { Context } from 'hono'

compress({
  filter: (c: Context) => true,
})

About

This project is a fork of bun-compression, which itself is a fork of elysia-compression.

Both projects were unmaintained and lacked many of the features I was looking for, so I started with them, but ended up improving and expanding many parts, eventually rewriting them from scratch.

This project was also inspired by hono/compress, expressjs/compression and elysia-compress.