What is decompress-response?
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);
});