Skip to content

Instantly share code, notes, and snippets.

@spion
Last active December 30, 2015 02:29
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 spion/2a2804e43e4d33aae208 to your computer and use it in GitHub Desktop.
Save spion/2a2804e43e4d33aae208 to your computer and use it in GitHub Desktop.
streams-es6.js
var B = require('bluebird'),
request = require('request'),
cheerio = require('cheerio'),
path = require('path'),
fs = require('fs');
B.promisifyAll(request)
var loadDocument = url =>
request.getAsync(url)
.spread((res, body) =>
cheerio.load(body));
var download = url =>
request(url).pipe(
fs.createWriteStream(
path.basename(url)));
// Download all images from an imgur page
var downloadAllImages = urls =>
loadDocument(url).then($ =>
$('.post a img').map((i, img) =>
downloadImage(URL.resolve(url, img.attribs.src))));
downloadImages('http://imgur.com/').done(
_ => console.log('done'),
e => console.error(e.stack));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment