"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.zipBundleDirectoryToBuffer = zipBundleDirectoryToBuffer;
const adm_zip_1 = __importDefault(require("adm-zip"));
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
/** Zip a local bundle directory for upload to Azure Sessions (no server-side extract). */
function zipBundleDirectoryToBuffer(bundleDirectory) {
    const root = path_1.default.resolve(bundleDirectory);
    if (!fs_1.default.existsSync(root)) {
        throw new Error(`Bundle directory not found: ${root}`);
    }
    const zip = new adm_zip_1.default();
    const addEntry = (absolutePath, relativePath) => {
        const stat = fs_1.default.statSync(absolutePath);
        if (stat.isDirectory()) {
            for (const name of fs_1.default.readdirSync(absolutePath)) {
                addEntry(path_1.default.join(absolutePath, name), path_1.default.posix.join(relativePath, name));
            }
            return;
        }
        zip.addFile(relativePath, fs_1.default.readFileSync(absolutePath));
    };
    for (const name of fs_1.default.readdirSync(root)) {
        addEntry(path_1.default.join(root, name), name);
    }
    return zip.toBuffer();
}
//# sourceMappingURL=zipBundleDirectory.js.map