Comparing version 0.1.1 to 0.2.0
var httpreq = require('./httpreq'); | ||
fs = require('fs') | ||
@@ -90,1 +91,14 @@ // get www.google.com | ||
// download a binary file: | ||
httpreq.get('https://ssl.gstatic.com/gb/images/k1_a31af7ac.png', {binary: true}, function (err, res){ | ||
if (err){ | ||
console.log(err); | ||
}else{ | ||
fs.writeFile(__dirname + '/test.png', res.body, function (err) { | ||
if(err) | ||
console.log("error writing file"); | ||
}); | ||
} | ||
}); | ||
/* | ||
Copyright (c) 2011 Sam Decrock <sam.decrock@gmail.com> | ||
Copyright (c) 2013 Sam Decrock <sam.decrock@gmail.com> | ||
@@ -53,3 +53,3 @@ MIT License | ||
exports.doRequest = function(o, callback){ | ||
var responsebody = ""; | ||
var chunks = []; | ||
var params; | ||
@@ -100,9 +100,11 @@ | ||
function requestResponse(res){ | ||
res.setEncoding('utf8'); | ||
res.on('data', function (chunk) { | ||
responsebody += chunk; | ||
chunks.push(chunk); | ||
}); | ||
res.on('end', function (err) { | ||
var responsebody = Buffer.concat(chunks); | ||
if(!o.binary) | ||
responsebody = responsebody.toString('utf8'); | ||
callback(null, {headers: res.headers, body: responsebody}); | ||
@@ -136,3 +138,3 @@ }); | ||
exports.uploadFiles = function(o, callback){ | ||
var responsebody = ""; | ||
var chunks = []; | ||
@@ -201,9 +203,11 @@ var reqUrl = url.parse(o.url); | ||
function requestResponse(res){ | ||
res.setEncoding('utf8'); | ||
res.on('data', function (chunk) { | ||
responsebody += chunk; | ||
chunks.push(chunk); | ||
}); | ||
res.on('end', function (err) { | ||
var responsebody = Buffer.concat(chunks); | ||
if(!o.binary) | ||
responsebody = responsebody.toString('utf8'); | ||
callback(null, {headers: res.headers, body: responsebody}); | ||
@@ -210,0 +214,0 @@ }); |
{ | ||
"name": "httpreq", | ||
"description": "node-httpreq is a node.js library to do HTTP(S) requests the easy way", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Sam Decrock", |
@@ -31,2 +31,3 @@ node-httpreq | ||
- cookies: an array of cookies | ||
- binary: true/false (default: false), if true, res.body will a buffer containing the binary data | ||
- callback(err, res): A callback function which is called when the request is complete. __res__ contains the headers ( __res.headers__ ) and the body ( __res.body__ ) | ||
@@ -84,2 +85,3 @@ | ||
- cookies: an array of cookies | ||
- binary: true/false (default: false), if true, res.body will a buffer containing the binary data | ||
- callback(err, res): A callback function which is called when the request is complete. __res__ contains the headers ( __res.headers__ ) and the body ( __res.body__ ) | ||
@@ -142,2 +144,3 @@ | ||
- cookies: an array of cookies | ||
- binary: true/false (default: false), if true, res.body will a buffer containing the binary data | ||
- callback(err, res): A callback function which is called when the request is complete. __res__ contains the headers ( __res.headers__ ) and the body ( __res.body__ ) | ||
@@ -178,2 +181,3 @@ | ||
- cookies: an array of cookies | ||
- binary: true/false (default: false), if true, res.body will a buffer containing the binary data | ||
- callback(err, res): A callback function which is called when the request is complete. __res__ contains the headers ( __res.headers__ ) and the body ( __res.body__ ) | ||
@@ -180,0 +184,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
74417
270
203
2