Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Created April 18, 2017 10:55
Show Gist options
  • Save andreasvirkus/32fe514d02b0d72ee7226e571b08992d to your computer and use it in GitHub Desktop.
Save andreasvirkus/32fe514d02b0d72ee7226e571b08992d to your computer and use it in GitHub Desktop.
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