
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
decompress-response
Advanced tools
The decompress-response npm package is used to decompress HTTP responses that are compressed. This is useful when making HTTP requests and the server responds with compressed data, such as gzip or deflate. The package automatically detects the encoding and decompresses the response so that it can be easily processed in its uncompressed form.
Decompressing HTTP responses
This code sample demonstrates how to use decompress-response to decompress an HTTP response. The 'http.get' method is used to make a GET request to a server. The response is then passed through the decompressResponse function, which returns a stream with the decompressed response. Finally, the decompressed data is piped to the standard output.
const http = require('http');
const decompressResponse = require('decompress-response');
http.get('http://example.com', (res) => {
res = decompressResponse(res);
res.pipe(process.stdout);
});
The pump package is a small node module that pipes streams together and destroys all of them if one of them closes. While it does not provide decompression functionality by itself, it can be used in conjunction with stream-compression modules to handle errors and clean up streams properly after decompression.
Got is a human-friendly and powerful HTTP request library for Node.js. Got supports decompression of HTTP responses out of the box, similar to decompress-response, but it also provides a much richer set of features for making HTTP requests, such as retries, pagination, and more.
node-fetch is a light-weight module that brings the Fetch API to Node.js. It allows you to make HTTP requests similar to the way you would in a browser. The Fetch API supports transparent decompression of responses, which is a feature also provided by decompress-response, but node-fetch offers a broader feature set for making requests and handling responses.
Axios is a promise-based HTTP client for the browser and Node.js. It supports response data decompression, much like decompress-response. However, axios provides a wide range of features such as interceptors, automatic transforms for JSON data, and client-side protection against XSRF.
Decompress a HTTP response if needed
Decompresses the response from http.request
if it's gzipped, deflated or compressed with Brotli, otherwise just passes it through.
Used by got
.
npm install decompress-response
import http from 'node:http';
import decompressResponse from 'decompress-response';
http.get('https://sindresorhus.com', response => {
response = decompressResponse(response);
});
Returns the decompressed HTTP response stream.
Type: http.IncomingMessage
The HTTP incoming stream with compressed data.
FAQs
Decompress a HTTP response if needed
We found that decompress-response demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.