Created
April 21, 2024 20:57
-
-
Save maksimr/e6f997cd51a8d8e11c7ce10612d7b10d 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
async function fetchZip(url, outDir) { | |
const os = require('os'); | |
const path = require('path'); | |
const fs = require('fs'); | |
const AdmZip = require("adm-zip"); | |
const pipeline = require('stream/promises').pipeline; | |
const zipName = path.basename(url); | |
const zipFilePath = path.join(os.tmpdir(), zipName); | |
const response = await fetch(url); | |
await pipeline(response.body, fs.createWriteStream(zipFilePath)); | |
const zip = new AdmZip(zipFilePath); | |
zip.extractAllTo(outDir, true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment