"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.FileUploader=void 0;const urllib_1=require("urllib"),faas_server_utils_1=require("@alipay/faas-server-utils"),debug=(0,faas_server_utils_1.debuglog)("faas-server-sdk:Storage");class FileUploader{static#e;async upload(a){const{uploadURL:t,fileID:s,fileContent:e}=a;let r,n;Buffer.isBuffer(e)?n=e:r=e;const o=await(0,urllib_1.request)(t,{method:"PUT",content:n,stream:r,timeout:6e4});return debug("uploadFile fileID: %o, uploadURL: %o got response status: %o, headers: %o, body: %o",s,t,o.status,o.headers,o.data.toString()),{statusCode:o.status}}async download(a){const{fileID:t,downloadURL:s}=a,e=await(0,urllib_1.request)(s,{timeout:6e4});return debug("downloadFile fileID: %o, downloadURL: %o got response status: %o, headers: %o, body length: %o",t,s,e.status,e.headers,e.data.length),{fileContent:e.data,statusCode:e.status}}static create(){return FileUploader.#e||(FileUploader.#e=new FileUploader),FileUploader.#e}}exports.FileUploader=FileUploader;