function d() {
var data = [
{
img: "http://wow.zamimg.com/images/hearthstone/cards/enus/original/OG_134.png",
cardId: "yogg"
},
{
img: "http://wow.zamimg.com/images/hearthstone/cards/enus/original/HERO_07.png",
cardId: "nzoth"
}
];
var async = require('async')
async.each(data, (card, next) => {
if("img" in card) {
var img = require('fs').createWriteStream(card.cardId + ".png");
require("http").get(card.img, (res) => {
res.pipe(img).on('end', next)
});
}
}
, () => {
console.log(done)
})
}
const { DownloaderHelper } = require('node-downloader-helper');
const dl = new DownloaderHelper('https://proof.ovh.net/files/1Gb.dat', __dirname);
dl.on('end', () => console.log('Download Completed'))
dl.start();
export const streamFile = async (imageUrl: string, imageName: string) => {
const filename: string = `${process.env.IMG_DIR}/${imageName}`
const writeFile: fs.WriteStream = fs.createWriteStream(filename)
const res: request.Request = await request(imageUrl)
res.pipe(writeFile)
res.on('data', (chunk: Buffer) => writeFile.write(chunk))
res.on('complete', () => {
writeFile.end()
console.info('Streaming file success')
})
res.on('error', () => console.error('Streaming file error'))
}