Created
June 6, 2016 13:46
-
-
Save riston/40ff0b7caf956091b6c8662b8d5c998d to your computer and use it in GitHub Desktop.
Download file without extra libraries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require("http"); | |
var fs = require("fs"); | |
function getFile(url, saveFile, cb) { | |
var request = http.get(url, response => { | |
var write$ = fs.createWriteStream(saveFile); | |
write$.on("error", cb); | |
write$.on("finish", () => cb(null)); | |
response.pipe(write$); | |
}); | |
request.on("error", cb); | |
} | |
// Get assets for the | |
// getFile("http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg", "./tmp/test.jpg", err => { | |
// if (err) console.log(err); | |
// }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment