Skip to content

Instantly share code, notes, and snippets.

@Rokt33r

Rokt33r/.js

Created Sep 25, 2016
Embed
What would you like to do?
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
You can’t perform that action at this time.