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

crequest

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crequest - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

test.js

57

index.js
"use strict";
var zlib = require("zlib");
var stream = require("stream"),
util = require("util"),
zlib = require("zlib");

@@ -8,2 +10,44 @@ var copy = require("request/lib/copy"),

var ConditionalUnzip = function() {
stream.Transform.call(this);
var dests = [],
source;
this.on("pipe", function(src) {
if (src instanceof _request.Request) {
src.on("response", function(res) {
if (["gzip", "deflate"].some(function(enc) {
return res.headers["content-encoding"] === enc;
})) {
// response was compressed
source = res.pipe(zlib.createUnzip());
} else {
source = res;
}
dests.forEach(function(dest) {
source.pipe(dest);
});
});
}
});
this.pipe = function(dest) {
if (source) {
source.pipe(dest);
} else {
dests.push(dest);
}
};
this._transform = function(buffer, encoding, callback) {
// drop (compressed) chunks on the floor since we can't get request to stop
// sending them to us
return callback();
};
};
util.inherits(ConditionalUnzip, stream.Transform);
var request = function(uri, options, callback) {

@@ -40,2 +84,5 @@

// provide a default callback
callback = callback || function() {};
options.headers = options.headers || {};

@@ -46,3 +93,3 @@

return new _request.Request(options)
var request = new _request.Request(options)
.on("response", function(res) {

@@ -65,3 +112,5 @@ var stream = this;

})
.on("error", console.warn)
.on("error", function(err) {
console.warn(err.stack);
})
.on("end", function() {

@@ -91,2 +140,4 @@ res.body = Buffer.concat(chunks);

});
return request.pipe(new ConditionalUnzip());
};

@@ -93,0 +144,0 @@

2

package.json
{
"name": "crequest",
"version": "0.1.2",
"version": "0.1.3",
"description": "request+compression--drop-in wrapper for 'request'",

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

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