Created
October 19, 2023 16:44
-
-
Save kennarddh/6e0ec4132a502633f9999c20edc76926 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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