"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendZip = sendZip;
const archiver_1 = __importDefault(require("archiver"));
const fs_1 = __importDefault(require("fs"));
/**
 * Send a zip file as a download response.
 * Replacement for express-easy-zip using archiver directly.
 */
function sendZip(res, options) {
    const { files, filename } = options;
    res.setHeader('Content-Type', 'application/zip');
    res.setHeader('Content-Disposition', `attachment; filename="${filename}.zip"`);
    const archive = (0, archiver_1.default)('zip', {
        zlib: { level: 9 }
    });
    archive.on('error', (err) => {
        console.error('Zip archive error:', err);
        if (!res.headersSent) {
            res.status(500).send('Error creating zip file');
        }
    });
    archive.pipe(res);
    for (const file of files) {
        const stat = fs_1.default.statSync(file.path);
        if (stat.isDirectory()) {
            archive.directory(file.path, file.name);
        }
        else {
            archive.file(file.path, { name: file.name });
        }
    }
    archive.finalize();
}
//# sourceMappingURL=zip.js.map