Skip to content

Instantly share code, notes, and snippets.

@Rokt33r
Created September 25, 2016 14:24
Show Gist options
  • Save Rokt33r/48643041c265a542557a1254bc11416c to your computer and use it in GitHub Desktop.
Save Rokt33r/48643041c265a542557a1254bc11416c to your computer and use it in GitHub Desktop.
got download pipe
'use strict'
const got = require('got')
const fs = require('fs')
const path = require('path')
let beta = fs.readFileSync(path.join(__dirname, 'beta.json'))
beta = JSON.parse(beta)
let data = []
for (let key in beta) {
let category = beta[key]
category.forEach((_item) => {
let item = Object.assign(_item, {category: key})
data.push(item)
})
}
try {
fs.mkdirSync(path.join(__dirname, 'download'))
} catch (err) {
}
data.forEach((item) => {
got.stream(item.img).pipe(fs.createWriteStream(path.join(__dirname, 'download', item.id + '.jpeg')))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment