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

fastify-compression

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-compression - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

test/base.test.js

14

index.js

@@ -13,3 +13,12 @@ 'use strict';

const supportedEncodings = ['gzip', 'deflate'];
const compressionStreams = {
gzip: zlib.createGzip,
deflate: zlib.createDeflate
}
if (opts.brotli) {
compressionStreams.br = opts.brotli.compressStream;
supportedEncodings.push('br');
}
fastify.addHook('onSend', compression)

@@ -22,3 +31,2 @@

if (shouldCompress(reply, method)) {
let payloadStream;
if (Buffer.byteLength(payload) < threshold) {

@@ -28,6 +36,6 @@ done();

}
payloadStream = stringToStream(payload);
let payloadStream = stringToStream(payload);
setVaryHeader(reply);
reply.header('Content-Encoding', method);
const compressionStream = method === 'gzip' ? zlib.createGzip() : zlib.createDeflate();
const compressionStream = compressionStreams[method]();

@@ -34,0 +42,0 @@ pump(payloadStream, compressionStream, onEnd.bind(request))

{
"name": "fastify-compression",
"version": "1.0.0",
"version": "1.1.0",
"description": "A compression plugin for fastify",
"main": "index.js",
"scripts": {
"unit": "tap test/*",
"unit": "tap test/*.test.js",
"test": "npm run lint && npm run unit",

@@ -37,6 +37,7 @@ "lint": "./node_modules/eslint/bin/eslint.js index.js lib/*",

"eslint": "^4.19.1",
"iltorb": "^2.0.3",
"fastify": "^1.2.1",
"request": "^2.85.0",
"tap": "^11.1.4"
"tap": "^12.0.0"
}
}

@@ -8,3 +8,3 @@ # fastify-compression

A compression plugin for [Fastify](http://fastify.io/). Supports `gzip` and `deflate`.
A compression plugin for [Fastify](http://fastify.io/). Supports `gzip`, `deflate` and `brotli`.

@@ -23,6 +23,8 @@ ## Usage

### compression(fastify, options, next)
Compresses the payload with `gzip` or `deflate` if the payload length is above the threshold and a `Accept-Encoding` header is send with the request. In case of an asterisk `*` in the `Accept-Encoding` header `gzip` will be chosen.
Compresses the payload with `gzip`, `brotli` or `deflate` if the payload length is above the threshold and a `Accept-Encoding` header is send with the request. In case of an asterisk `*` in the `Accept-Encoding` header `gzip` will be chosen.
### options
#### threshold (optional)
A `number` that specifies the threshold used to determine if compression should be applied. Defaults to `1024`.
#### brotli
To enable Brotli compression pass the [iltorb](https://www.npmjs.com/package/iltorb) module with the `brotli` option.

@@ -29,0 +31,0 @@ ## License

Sorry, the diff of this file is not supported yet

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