New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fastify-compress

Package Overview
Dependencies
Maintainers
7
Versions
38
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 0.7.0 to 0.7.1

15

index.js

@@ -6,4 +6,4 @@ 'use strict'

const pump = require('pump')
const sts = require('string-to-stream')
const mimedb = require('mime-db')
const intoStream = require('into-stream')

@@ -18,3 +18,3 @@ function compressPlugin (fastify, opts, next) {

const threshold = typeof opts.threshold === 'number' ? opts.threshold : 1024
const compressibleTypes = opts.customTypes instanceof RegExp ? opts.customTypes : /^text\/|\+json$|\+text$|\+xml$/
const compressibleTypes = opts.customTypes instanceof RegExp ? opts.customTypes : /^text\/|\+json$|\+text$|\+xml$|octet-stream$/
const compressStream = {

@@ -35,3 +35,3 @@ gzip: zlib.createGzip,

if (payload == null) {
this.res.log.warn('compress: missing payload')
this.res.log.debug('compress: missing payload')
this.send(new Error('Internal server error'))

@@ -63,3 +63,3 @@ return

if (typeof payload.pipe !== 'function') {
if (typeof payload !== 'string') {
if (!Buffer.isBuffer(payload) && typeof payload !== 'string') {
payload = this.serialize(payload)

@@ -70,3 +70,3 @@ }

}
payload = sts(payload)
payload = intoStream(payload)
}

@@ -85,3 +85,3 @@

if (payload == null) {
reply.res.log.warn('compress: missing payload')
reply.res.log.debug('compress: missing payload')
return next()

@@ -116,3 +116,3 @@ }

}
payload = sts(payload)
payload = intoStream(payload)
}

@@ -123,3 +123,2 @@

.removeHeader('content-length')
var stream = compressStream[encoding]()

@@ -126,0 +125,0 @@ pump(payload, stream, onEnd.bind(reply))

{
"name": "fastify-compress",
"version": "0.7.0",
"version": "0.7.1",
"description": "Fastify compression utils",

@@ -8,5 +8,5 @@ "main": "index.js",

"fastify-plugin": "^1.0.0",
"into-stream": "^4.0.0",
"mime-db": "^1.33.0",
"pump": "^3.0.0",
"string-to-stream": "^1.1.0"
"pump": "^3.0.0"
},

@@ -13,0 +13,0 @@ "devDependencies": {

@@ -0,0 +0,0 @@ # fastify-compress

@@ -254,2 +254,140 @@ 'use strict'

test('Should compress buffer (gzip)', t => {
t.plan(2)
const fastify = Fastify()
fastify.register(compressPlugin, { global: false, threshold: 0 })
const buf = Buffer.from('hello world')
fastify.get('/', (req, reply) => {
reply.compress(buf)
})
fastify.inject({
url: '/',
method: 'GET',
headers: {
'accept-encoding': 'gzip'
}
}, (err, res) => {
t.error(err)
const payload = zlib.gunzipSync(res.rawPayload)
t.strictEqual(payload.toString('utf-8'), buf.toString())
})
})
test('Should compress buffer (deflate)', t => {
t.plan(2)
const fastify = Fastify()
fastify.register(compressPlugin, { global: false, threshold: 0 })
const buf = Buffer.from('hello world')
fastify.get('/', (req, reply) => {
reply.compress(buf)
})
fastify.inject({
url: '/',
method: 'GET',
headers: {
'accept-encoding': 'deflate'
}
}, (err, res) => {
t.error(err)
const payload = zlib.inflateSync(res.rawPayload)
t.strictEqual(payload.toString('utf-8'), buf.toString())
})
})
test('Should compress buffer (brotli)', t => {
t.plan(2)
const fastify = Fastify()
fastify.register(compressPlugin, { global: false, brotli, threshold: 0 })
const buf = Buffer.from('hello world')
fastify.get('/', (req, reply) => {
reply.compress(buf)
})
fastify.inject({
url: '/',
method: 'GET',
headers: {
'accept-encoding': 'br'
}
}, (err, res) => {
t.error(err)
const payload = brotli.decompressSync(res.rawPayload)
t.strictEqual(payload.toString('utf-8'), buf.toString())
})
})
test('Should compress buffer (gzip) - global', t => {
t.plan(2)
const fastify = Fastify()
fastify.register(compressPlugin, { threshold: 0 })
const buf = Buffer.from('hello world')
fastify.get('/', (req, reply) => {
reply.send(buf)
})
fastify.inject({
url: '/',
method: 'GET',
headers: {
'accept-encoding': 'gzip'
}
}, (err, res) => {
t.error(err)
const payload = zlib.gunzipSync(res.rawPayload)
t.strictEqual(payload.toString('utf-8'), buf.toString())
})
})
test('Should compress buffer (deflate) - global', t => {
t.plan(2)
const fastify = Fastify()
fastify.register(compressPlugin, { threshold: 0 })
const buf = Buffer.from('hello world')
fastify.get('/', (req, reply) => {
reply.send(buf)
})
fastify.inject({
url: '/',
method: 'GET',
headers: {
'accept-encoding': 'deflate'
}
}, (err, res) => {
t.error(err)
const payload = zlib.inflateSync(res.rawPayload)
t.strictEqual(payload.toString('utf-8'), buf.toString())
})
})
test('Should compress buffer (brotli) - global', t => {
t.plan(2)
const fastify = Fastify()
fastify.register(compressPlugin, { brotli, threshold: 0 })
const buf = Buffer.from('hello world')
fastify.get('/', (req, reply) => {
reply.send(buf)
})
fastify.inject({
url: '/',
method: 'GET',
headers: {
'accept-encoding': 'br'
}
}, (err, res) => {
t.error(err)
const payload = brotli.decompressSync(res.rawPayload)
t.strictEqual(payload.toString('utf-8'), buf.toString())
})
})
test('Should compress json data (gzip)', t => {

@@ -256,0 +394,0 @@ t.plan(2)

Sorry, the diff of this file is not supported yet

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