"use strict";var __awaiter=this&&this.__awaiter||function(e,t,i,r){return new(i||(i=Promise))((function(n,o){function u(e){try{s(r.next(e))}catch(e){o(e)}}function a(e){try{s(r.throw(e))}catch(e){o(e)}}function s(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(u,a)}s((r=r.apply(e,t||[])).next())}))},__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})}function downloadFile(e,t,i){return __awaiter(this,void 0,void 0,(function*(){if(fs_1.default.existsSync(t)||fs_1.default.mkdirSync(t),fs_1.default.existsSync(path_1.default.join(t,i)))return;const r=path_1.default.resolve(t,i),n=fs_1.default.createWriteStream(r);try{if(path_1.default.isAbsolute(e)&&".zip"===path_1.default.extname(e))fs_1.default.createReadStream(e).pipe(n);else{(yield(0,axios_1.default)({url:e,method:"GET",responseType:"stream"})).data.pipe(n)}}catch(e){return deleteFile(r),Promise.reject(e)}return new Promise((e,t)=>{n.on("finish",e),n.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;