Skip to content

Instantly share code, notes, and snippets.

@stephaneerard
Created March 4, 2016 16:51
Show Gist options
  • Select an option

  • Save stephaneerard/f4549da7fde609efdd36 to your computer and use it in GitHub Desktop.

Select an option

Save stephaneerard/f4549da7fde609efdd36 to your computer and use it in GitHub Desktop.
function _download() {
return new Promise(function (resolve, reject) {
debug("download", image.url);
var tmpName = tmp.tmpNameSync();
var writable = fs.createWriteStream(tmpName);
var streamSource = request(image.url);
streamSource
.on("response", function (res) {
debug("download ended", res.statusCode);
})
.on("end", function () {
resolve(fs.createReadStream(tmpName));
})
.on("error", function (err) {
debug("download error", err);
})
.pipe(writable)
;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment