UNPKG

@controlplane/cli

Version:

Control Plane Corporation CLI

35 lines 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const fs = require("fs"); const path = require("path"); const AdmZip = require("adm-zip"); class ArchiveManager { /** * Compresses files and directories into a ZIP archive and returns a buffer. * @param paths Array of file or directory paths to compress. * @returns Buffer of the compressed ZIP archive. */ async compress(paths) { const zip = new AdmZip(); try { // Add each path (file or directory) to the ZIP archive for (const filePath of paths) { if (fs.statSync(filePath).isDirectory()) { // Recursively add a directory to the ZIP zip.addLocalFolder(filePath, path.basename(filePath)); } else { // Add a single file to the ZIP zip.addLocalFile(filePath); } } // Generate the ZIP archive as a buffer return zip.toBuffer(); } catch (error) { throw new Error(`Error compressing files: ${error.message}`); } } } exports.default = ArchiveManager; //# sourceMappingURL=index.js.map