"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.decodeString=exports.unzip=exports.downloadFile=exports.deleteFile=void 0;const fs_1=__importDefault(require("fs")),axios_1=__importDefault(require("axios")),path_1=__importDefault(require("path")),crypto_1=__importDefault(require("crypto")),utils_1=require("../../../utils/utils");function deleteFile(e){fs_1.default.unlink(e,e=>{if(e)throw e})}async function downloadFile(e,t,r){if(fs_1.default.existsSync(t)||fs_1.default.mkdirSync(t),fs_1.default.existsSync(path_1.default.join(t,r)))return;const i=path_1.default.resolve(t,r),o=fs_1.default.createWriteStream(i);try{if(path_1.default.isAbsolute(e)&&".zip"===path_1.default.extname(e))fs_1.default.createReadStream(e).pipe(o);else{(await(0,axios_1.default)({url:e,method:"GET",responseType:"stream"})).data.pipe(o)}}catch(e){return deleteFile(i),Promise.reject(e)}return new Promise((e,t)=>{o.on("finish",e),o.on("error",t)})}function unzip(e,t){return(0,utils_1.unzipFile)(e,t)}function decodeString(e){const t=crypto_1.default.createHash("sha1");return t.update(e),t.digest("hex")}exports.deleteFile=deleteFile,exports.downloadFile=downloadFile,exports.unzip=unzip,exports.decodeString=decodeString;