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

fastify-compress

Package Overview
Dependencies
Maintainers
2
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.3.0 to 0.4.0

13

index.js

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

function compress (payload) {
if (!payload) {
if (payload == null) {
this.res.log.warn('compress: missing payload')

@@ -59,3 +59,3 @@ this.send(new Error('Internal server error'))

if (payload._readableState === undefined) {
if (typeof payload.pipe !== 'function') {
if (typeof payload !== 'string') {

@@ -77,3 +77,3 @@ payload = this.serialize(payload)

function onSend (req, reply, payload, next) {
if (!payload) {
if (payload == null) {
reply.res.log.warn('compress: missing payload')

@@ -105,6 +105,3 @@ return next()

if (payload._readableState === undefined) {
if (typeof payload !== 'string') {
payload = reply.serialize(payload)
}
if (typeof payload.pipe !== 'function') {
if (Buffer.byteLength(payload) < threshold) {

@@ -160,4 +157,4 @@ return next()

module.exports = fp(compressPlugin, {
fastify: '>=0.39.1',
fastify: '>=0.40.0',
name: 'fastify-compress'
})
{
"name": "fastify-compress",
"version": "0.3.0",
"version": "0.4.0",
"description": "Fastify compression utils",

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

"mime-db": "^1.32.0",
"pump": "^2.0.0",
"pump": "^2.0.1",
"string-to-stream": "^1.1.0"
},
"devDependencies": {
"fastify": "^0.39.1",
"fastify": "^0.40.0",
"iltorb": "^2.0.3",
"jsonstream": "^1.0.3",
"standard": "^10.0.3",

@@ -17,0 +18,0 @@ "tap": "^11.0.1"

@@ -8,2 +8,3 @@ 'use strict'

const fs = require('fs')
const JSONStream = require('jsonstream')
const createReadStream = fs.createReadStream

@@ -643,1 +644,53 @@ const readFileSync = fs.readFileSync

})
test('should support stream1 (reply compress)', t => {
t.plan(3)
const fastify = Fastify()
fastify.register(compressPlugin, { global: false })
fastify.get('/', (req, reply) => {
const stream = JSONStream.stringify()
reply.type('text/plain').compress(stream)
stream.write({ hello: 'world' })
stream.end({ a: 42 })
})
fastify.inject({
url: '/',
method: 'GET',
headers: {
'accept-encoding': 'gzip'
}
}, (err, res) => {
t.error(err)
t.strictEqual(res.headers['content-encoding'], 'gzip')
const payload = zlib.gunzipSync(res.rawPayload)
t.deepEqual(JSON.parse(payload.toString()), [{ hello: 'world' }, { a: 42 }])
})
})
test('should support stream1 (global hook)', t => {
t.plan(3)
const fastify = Fastify()
fastify.register(compressPlugin, { threshold: 0 })
fastify.get('/', (req, reply) => {
const stream = JSONStream.stringify()
reply.type('text/plain').send(stream)
stream.write({ hello: 'world' })
stream.end({ a: 42 })
})
fastify.inject({
url: '/',
method: 'GET',
headers: {
'accept-encoding': 'gzip'
}
}, (err, res) => {
t.error(err)
t.strictEqual(res.headers['content-encoding'], 'gzip')
const payload = zlib.gunzipSync(res.rawPayload)
t.deepEqual(JSON.parse(payload.toString()), [{ hello: 'world' }, { a: 42 }])
})
})
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