"use strict";
exports.ids = [
    "419"
];
exports.modules = {
    "./webpack/webpack-lib/zip.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
        __webpack_require__.d(__webpack_exports__, {
            downloadAndExtractZip: ()=>downloadAndExtractZip
        });
        var path__rspack_import_0 = __webpack_require__("path");
        var adm_zip__rspack_import_1 = __webpack_require__("adm-zip");
        var adm_zip__rspack_import_1_default = /*#__PURE__*/ __webpack_require__.n(adm_zip__rspack_import_1);
        var _messages__rspack_import_2 = __webpack_require__("./webpack/webpack-lib/messages.ts");
        async function downloadAndExtractZip(url, targetPath) {
            const urlNoSearchParams = url.split('?')[0];
            try {
                console.log(_messages__rspack_import_2.Ud(urlNoSearchParams));
                const res = await fetch(url, {
                    redirect: 'follow'
                });
                if (!res.ok || !res.body) throw new Error(`HTTP ${res.status} ${res.statusText}`);
                const contentType = String(res.headers.get('content-type') || '');
                const isZipExt = '.zip' === path__rspack_import_0.extname(urlNoSearchParams).toLowerCase();
                const isZipType = /zip|octet-stream/i.test(contentType);
                if (!isZipExt && !isZipType) throw new Error(`${_messages__rspack_import_2.tc(urlNoSearchParams, contentType)}`);
                const extname = path__rspack_import_0.extname(urlNoSearchParams);
                const basename = path__rspack_import_0.basename(urlNoSearchParams, extname);
                const destinationPath = path__rspack_import_0.join(targetPath, basename);
                console.log(_messages__rspack_import_2.gC(destinationPath));
                const arrayBuffer = await res.arrayBuffer();
                const zipBuffer = Buffer.from(arrayBuffer);
                const zip = new (adm_zip__rspack_import_1_default())(zipBuffer);
                zip.extractAllTo(destinationPath, true);
                console.log(_messages__rspack_import_2.zM());
                return destinationPath;
            } catch (error) {
                console.error(_messages__rspack_import_2.GW(error));
                const err = new Error(`${_messages__rspack_import_2.GW(error)}`);
                err.code = 'EZIP';
                throw err;
            }
        }
    }
};
