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

decompress-response

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

decompress-response - npm Package Compare versions

Comparing version 5.0.0 to 6.0.0

48

index.js
'use strict';
const {
pipeline: streamPipeline,
PassThrough: PassThroughStream
} = require('stream');
const {Transform, PassThrough} = require('stream');
const zlib = require('zlib');
const mimicResponse = require('mimic-response');
const decompressResponse = response => {
module.exports = response => {
const contentEncoding = (response.headers['content-encoding'] || '').toLowerCase();

@@ -19,25 +16,44 @@

if (isBrotli && typeof zlib.createBrotliDecompress !== 'function') {
response.destroy(new Error('Brotli is not supported on Node.js < 12'));
return response;
}
const decompress = isBrotli ? zlib.createBrotliDecompress() : zlib.createUnzip();
const stream = new PassThroughStream();
let isEmpty = true;
decompress.on('error', error => {
// Ignore empty response
if (error.code === 'Z_BUF_ERROR') {
stream.end();
const checker = new Transform({
transform(data, _encoding, callback) {
isEmpty = false;
callback(null, data);
},
flush(callback) {
callback();
}
});
const finalStream = new PassThrough({
autoDestroy: false,
destroy(error, callback) {
response.destroy();
callback(error);
}
});
const decompressStream = isBrotli ? zlib.createBrotliDecompress() : zlib.createUnzip();
decompressStream.once('error', error => {
if (isEmpty && !response.readable) {
finalStream.end();
return;
}
stream.emit('error', error);
finalStream.destroy(error);
});
const finalStream = streamPipeline(response, decompress, stream, () => {});
mimicResponse(response, finalStream);
response.pipe(checker).pipe(decompressStream).pipe(finalStream);
return finalStream;
};
module.exports = decompressResponse;
{
"name": "decompress-response",
"version": "5.0.0",
"version": "6.0.0",
"description": "Decompress a HTTP response if needed",
"license": "MIT",
"repository": "sindresorhus/decompress-response",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},

@@ -40,12 +41,17 @@ "engines": {

"dependencies": {
"mimic-response": "^2.0.0"
"mimic-response": "^3.1.0"
},
"devDependencies": {
"@types/node": "^12.7.1",
"@types/node": "^14.0.1",
"ava": "^2.2.0",
"get-stream": "^5.0.0",
"pify": "^4.0.1",
"tsd": "^0.10.0",
"xo": "^0.25.3"
"pify": "^5.0.0",
"tsd": "^0.11.0",
"xo": "^0.30.0"
},
"xo": {
"rules": {
"@typescript-eslint/prefer-readonly-parameter-types": "off"
}
}
}

@@ -1,2 +0,2 @@

# decompress-response [![Build Status](https://travis-ci.org/sindresorhus/decompress-response.svg?branch=master)](https://travis-ci.org/sindresorhus/decompress-response)
# decompress-response [![Build Status](https://travis-ci.com/sindresorhus/decompress-response.svg?branch=master)](https://travis-ci.com/sindresorhus/decompress-response)

@@ -9,3 +9,2 @@ > Decompress a HTTP response if needed

## Install

@@ -17,3 +16,2 @@

## Usage

@@ -30,3 +28,2 @@

## API

@@ -44,3 +41,2 @@

---

@@ -47,0 +43,0 @@

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