Created
October 14, 2013 16:32
-
-
Save evanmoran/6978386 to your computer and use it in GitHub Desktop.
Download file with Node
This file contains 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
// download: download the url to string | |
utl.download = function(url, cb){ | |
var options = require('url').parse(url), | |
httpx = url.startsWith(url, 'https:') ? https : http, | |
data = "", | |
req = httpx.request(options, function(res){ | |
res.setEncoding("utf8") | |
res.on("data", function(chunk){ | |
return data += chunk; | |
}) | |
return res.on("end", function(){ | |
return cb(null, data, url); | |
}) | |
}) | |
return req.end() | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment