Skip to content

Instantly share code, notes, and snippets.

@kennarddh
Created October 19, 2023 16:44
Show Gist options
  • Select an option

  • Save kennarddh/6e0ec4132a502633f9999c20edc76926 to your computer and use it in GitHub Desktop.

Select an option

Save kennarddh/6e0ec4132a502633f9999c20edc76926 to your computer and use it in GitHub Desktop.
const fs = require('fs')
const path = require('path')
const data = JSON.parse(fs.readFileSync('./data.json'))
const outputDir = path.resolve('./output/')
const main = async () => {
for (const [fileName, url] of data) {
console.log({ fileName })
const response = await fetch(url)
const blob = await response.blob()
console.log({ blob })
const buffer = Buffer.from(await blob.arrayBuffer())
fs.writeFile(path.join(outputDir, fileName), buffer, () =>
console.log(`${fileName} saved`)
)
}
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment