Created
April 18, 2017 10:55
-
-
Save andreasvirkus/32fe514d02b0d72ee7226e571b08992d to your computer and use it in GitHub Desktop.
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
import fs from 'fs'; | |
import request from 'request'; | |
/** | |
* Download and save a file to the project root | |
* | |
* Courtesy of http://stackoverflow.com/a/12751657/2803743 | |
*/ | |
export const download = function(uri, filename, callback) { | |
request.head(uri, function(err, res, body) { | |
console.log('content-type:', res.headers['content-type']); | |
console.log('content-length:', res.headers['content-length']); | |
request(uri).pipe(fs.createWriteStream(filename)).on('close', callback); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment