Skip to content

Instantly share code, notes, and snippets.

@maksimr
Created April 21, 2024 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maksimr/e6f997cd51a8d8e11c7ce10612d7b10d to your computer and use it in GitHub Desktop.
Save maksimr/e6f997cd51a8d8e11c7ce10612d7b10d to your computer and use it in GitHub Desktop.
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