Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Fix wrong binary encoding
Browse files Browse the repository at this point in the history
Due to #1912 we were writing binaries to disk with the encoding.
We need to do some additional juggling when dealing with binary
data.
  • Loading branch information
xzyfer committed Mar 11, 2018
1 parent 0b6baf3 commit b4f82d8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
10 changes: 6 additions & 4 deletions scripts/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function download(url, dest, cb) {
console.log('Downloading binary from', url);

try {
request(url, downloadOptions(), function(err, response) {
request(url, downloadOptions(), function(err, response, buffer) {
if (err) {
reportError(err);
} else if (!successful(response)) {
Expand All @@ -60,10 +60,12 @@ function download(url, dest, cb) {
console.log('Download complete');

if (successful(response)) {
response.pipe(fs.createWriteStream(dest));
fs.createWriteStream(dest)
.on('error', cb)
.end(buffer, cb);
} else {
cb();
}

cb();
}
})
.on('response', function(response) {
Expand Down
3 changes: 2 additions & 1 deletion scripts/util/downloadoptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module.exports = function() {
timeout: 60000,
headers: {
'User-Agent': userAgent(),
}
},
encoding: null,
};

var proxyConfig = proxy();
Expand Down
9 changes: 6 additions & 3 deletions test/downloadoptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ describe('util', function() {
timeout: 60000,
headers: {
'User-Agent': ua(),
}
},
encoding: null,
};

assert.deepEqual(opts(), expected);
Expand All @@ -37,7 +38,8 @@ describe('util', function() {
timeout: 60000,
headers: {
'User-Agent': ua(),
}
},
encoding: null,
};

assert.deepEqual(opts(), expected);
Expand All @@ -61,7 +63,8 @@ describe('util', function() {
timeout: 60000,
headers: {
'User-Agent': ua(),
}
},
encoding: null,
};

assert.deepEqual(opts(), expected);
Expand Down

0 comments on commit b4f82d8

Please sign in to comment.