UNPKG

@clxrity/zip

Version:

A React zip utility library

39 lines (38 loc) 1.09 kB
// src/server/unzip.ts import AdmZip from "adm-zip"; import path from "path"; async function unzipFileServer(zipPath, extractTo, options) { const zip = new AdmZip(zipPath); zip.extractAllTo(extractTo, true); if (options?.onEachFile) { await Promise.all( zip.getEntries().map(async (entry) => { if (!entry.isDirectory) { const filePath = path.join(extractTo, entry.entryName); await options.onEachFile?.(filePath); } }) ); } if (options?.onComplete) { await options.onComplete( zip.getEntries().map((entry) => entry.entryName) ); } } // src/server/zip.ts import AdmZip2 from "adm-zip"; async function zipFilesServer(inputPaths, outputPath, options) { const zip = new AdmZip2(); const paths = options?.onBeforeZip ? await options.onBeforeZip(inputPaths) : inputPaths; paths.forEach((file) => zip.addLocalFile(file)); zip.writeZip(outputPath); if (options?.onAfterZip) { await options.onAfterZip(outputPath); } } export { unzipFileServer, zipFilesServer }; //# sourceMappingURL=index.js.map