Skip to content

Instantly share code, notes, and snippets.

@Daymannovaes
Last active January 27, 2017 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daymannovaes/54663e0718f0ded40285d0666f937179 to your computer and use it in GitHub Desktop.
Save Daymannovaes/54663e0718f0ded40285d0666f937179 to your computer and use it in GitHub Desktop.
// first run npm install -g request
function requestFile(url, callback) {
return require('request').get(url, callback);
}
let url = 'https://www.google.com.br/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png';
// stream test
requestFile(url).pipe(require('fs').createWriteStream('image-stream.png'));
// buffer test
requestFile(url, (error, response, body) => {
require('fs').writeFileSync('image-sync.png', body);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment