Commit b4f82d80 by xzyfer Committed by Michael Mifsud

Fix wrong binary encoding

Due to #1912 we were writing binaries to disk with the encoding.
We need to do some additional juggling when dealing with binary
data.
parent 0b6baf38
...@@ -51,7 +51,7 @@ function download(url, dest, cb) { ...@@ -51,7 +51,7 @@ function download(url, dest, cb) {
console.log('Downloading binary from', url); console.log('Downloading binary from', url);
try { try {
request(url, downloadOptions(), function(err, response) { request(url, downloadOptions(), function(err, response, buffer) {
if (err) { if (err) {
reportError(err); reportError(err);
} else if (!successful(response)) { } else if (!successful(response)) {
...@@ -60,11 +60,13 @@ function download(url, dest, cb) { ...@@ -60,11 +60,13 @@ function download(url, dest, cb) {
console.log('Download complete'); console.log('Download complete');
if (successful(response)) { if (successful(response)) {
response.pipe(fs.createWriteStream(dest)); fs.createWriteStream(dest)
} .on('error', cb)
.end(buffer, cb);
} else {
cb(); cb();
} }
}
}) })
.on('response', function(response) { .on('response', function(response) {
var length = parseInt(response.headers['content-length'], 10); var length = parseInt(response.headers['content-length'], 10);
......
...@@ -18,7 +18,8 @@ module.exports = function() { ...@@ -18,7 +18,8 @@ module.exports = function() {
timeout: 60000, timeout: 60000,
headers: { headers: {
'User-Agent': userAgent(), 'User-Agent': userAgent(),
} },
encoding: null,
}; };
var proxyConfig = proxy(); var proxyConfig = proxy();
......
...@@ -12,7 +12,8 @@ describe('util', function() { ...@@ -12,7 +12,8 @@ describe('util', function() {
timeout: 60000, timeout: 60000,
headers: { headers: {
'User-Agent': ua(), 'User-Agent': ua(),
} },
encoding: null,
}; };
assert.deepEqual(opts(), expected); assert.deepEqual(opts(), expected);
...@@ -37,7 +38,8 @@ describe('util', function() { ...@@ -37,7 +38,8 @@ describe('util', function() {
timeout: 60000, timeout: 60000,
headers: { headers: {
'User-Agent': ua(), 'User-Agent': ua(),
} },
encoding: null,
}; };
assert.deepEqual(opts(), expected); assert.deepEqual(opts(), expected);
...@@ -61,7 +63,8 @@ describe('util', function() { ...@@ -61,7 +63,8 @@ describe('util', function() {
timeout: 60000, timeout: 60000,
headers: { headers: {
'User-Agent': ua(), 'User-Agent': ua(),
} },
encoding: null,
}; };
assert.deepEqual(opts(), expected); assert.deepEqual(opts(), expected);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment