Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

koa-compress

Package Overview
Dependencies
Maintainers
11
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-compress

Compress middleware for koa

  • 5.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
272K
decreased by-13.26%
Maintainers
11
Weekly downloads
 
Created

What is koa-compress?

The koa-compress package is a middleware for the Koa framework that provides HTTP compression. It supports various compression algorithms like gzip, deflate, and brotli, which can significantly reduce the size of the response body and improve the performance of web applications.

What are koa-compress's main functionalities?

Basic Gzip Compression

This code demonstrates how to set up basic gzip compression in a Koa application using the koa-compress middleware. The middleware is added to the Koa app, and it will automatically compress the response body using gzip.

const Koa = require('koa');
const compress = require('koa-compress');

const app = new Koa();

app.use(compress());

app.use(ctx => {
  ctx.body = 'Hello World';
});

app.listen(3000);

Custom Compression Options

This code shows how to configure custom options for the compression middleware. The 'threshold' option specifies the minimum response size in bytes to compress, and the 'flush' option is used to control the zlib flush mode.

const Koa = require('koa');
const compress = require('koa-compress');

const app = new Koa();

app.use(compress({
  threshold: 2048,
  flush: require('zlib').Z_SYNC_FLUSH
}));

app.use(ctx => {
  ctx.body = 'Hello World';
});

app.listen(3000);

Brotli Compression

This code demonstrates how to enable Brotli compression with custom parameters. The 'br' option is used to configure Brotli-specific settings, such as the compression quality.

const Koa = require('koa');
const compress = require('koa-compress');
const zlib = require('zlib');

const app = new Koa();

app.use(compress({
  br: {
    params: {
      [zlib.constants.BROTLI_PARAM_QUALITY]: 4
    }
  }
}));

app.use(ctx => {
  ctx.body = 'Hello World';
});

app.listen(3000);

Other packages similar to koa-compress

FAQs

Package last updated on 09 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc