Socket
Socket
Sign inDemoInstall

@fastify/compress

Package Overview
Dependencies
Maintainers
19
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/compress - npm Package Compare versions

Comparing version 6.2.1 to 6.3.0

12

index.js

@@ -9,3 +9,3 @@ 'use strict'

const peek = require('peek-stream')
const Minipass = require('minipass')
const { Minipass } = require('minipass')
const pumpify = require('pumpify')

@@ -111,2 +111,4 @@ const encodingNegotiator = require('@fastify/accept-negotiator')

const defaultCompressibleTypes = /^text\/(?!event-stream)|\+json$|\+text$|\+xml$|octet-stream$/
function processCompressParams (opts) {

@@ -128,3 +130,7 @@ /* istanbul ignore next */

params.threshold = typeof opts.threshold === 'number' ? opts.threshold : 1024
params.compressibleTypes = opts.customTypes instanceof RegExp ? opts.customTypes : /^text\/(?!event-stream)|\+json$|\+text$|\+xml$|octet-stream$/
params.compressibleTypes = opts.customTypes instanceof RegExp
? opts.customTypes.test.bind(opts.customTypes)
: typeof opts.customTypes === 'function'
? opts.customTypes
: defaultCompressibleTypes.test.bind(defaultCompressibleTypes)
params.compressStream = {

@@ -467,3 +473,3 @@ br: () => ((opts.zlib || zlib).createBrotliCompress || zlib.createBrotliCompress)(params.brotliOptions),

function shouldCompress (type, compressibleTypes) {
if (compressibleTypes.test(type)) return true
if (compressibleTypes(type)) return true
const data = mimedb[type.split(';', 1)[0].trim().toLowerCase()]

@@ -470,0 +476,0 @@ if (data === undefined) return false

{
"name": "@fastify/compress",
"version": "6.2.1",
"version": "6.3.0",
"description": "Fastify compression utils",

@@ -12,3 +12,3 @@ "main": "index.js",

"mime-db": "^1.51.0",
"minipass": "^4.0.0",
"minipass": "^5.0.0",
"peek-stream": "^1.1.3",

@@ -20,3 +20,3 @@ "pump": "^3.0.0",

"@fastify/pre-commit": "^2.0.2",
"@types/node": "^18.0.0",
"@types/node": "^20.1.0",
"@typescript-eslint/eslint-plugin": "^5.9.0",

@@ -23,0 +23,0 @@ "@typescript-eslint/parser": "^5.9.0",

@@ -102,3 +102,4 @@ # @fastify/compress

### customTypes
[mime-db](https://github.com/jshttp/mime-db) is used to determine if a `content-type` should be compressed. You can compress additional content types via regular expression.
[mime-db](https://github.com/jshttp/mime-db) is used to determine if a `content-type` should be compressed. You can compress additional content types via regular expression or by providing a function.
```javascript

@@ -111,2 +112,11 @@ await fastify.register(

or
```javascript
await fastify.register(
import('@fastify/compress'),
{ customTypes: contentType => contentType.endsWith('x-protobuf') }
)
```
### onUnsupportedEncoding

@@ -113,0 +123,0 @@ When the encoding is not supported, a custom error response can be sent in place of the uncompressed payload by setting the `onUnsupportedEncoding(encoding, request, reply)` option to be a function that can modify the reply and return a `string | Buffer | Stream | Error` payload.

@@ -62,2 +62,4 @@ import {

type CompressibleContentTypeFunction = (contentType: string) => boolean;
declare namespace fastifyCompress {

@@ -67,3 +69,3 @@

brotliOptions?: BrotliOptions;
customTypes?: RegExp;
customTypes?: RegExp | CompressibleContentTypeFunction;
encodings?: EncodingToken[];

@@ -70,0 +72,0 @@ forceRequestEncoding?: EncodingToken;

@@ -31,2 +31,6 @@ import fastify, { FastifyInstance } from 'fastify'

app.register(fastifyCompress, {
customTypes: value => value === 'application/json'
})
app.get('/test-one', async (request, reply) => {

@@ -33,0 +37,0 @@ expectType<void>(reply.compress(stream))

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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