Skip to content

Commit d2b5656

Browse files
committed
white magic
1 parent 64e3a91 commit d2b5656

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/helpers/child-process.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,20 @@ process.on('message', function(task) {
4747
*/
4848
function downloadFile(cb) {
4949
if(task.file_path) {
50+
var stream = fs.createWriteStream(path);
51+
52+
var binaryParser = function binaryParser(res, cb) {
53+
stream.on('end', cb);
54+
res.pipe(stream);
55+
};
56+
5057
// Download the file
5158
var apiUrl = url.parse(task.file_path, false, true);
5259
request(apiUrl.protocol + "//" + apiUrl.host)
5360
.get(apiUrl.path)
5461
.expect(200)
55-
.end(function(err, res) {
62+
.parse(binaryParser)
63+
.end(function(err) {
5664
if(err) {
5765
if(err.toString().match(/410/)) {
5866
err.skip = true;
@@ -62,7 +70,8 @@ process.on('message', function(task) {
6270
}
6371
return cb(err);
6472
}
65-
fs.writeFile(path, res.text, {encoding: 'binary'}, cb);
73+
stream.end();
74+
cb();
6675
});
6776
}
6877
else {

0 commit comments

Comments
 (0)