1 line
17 KiB
JavaScript
1 line
17 KiB
JavaScript
define(["exports"],function(_exports){function _createForOfIteratorHelper(r,e){var o,a,u,n,t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return u=!(a=!0),{s:function(){t=t.call(r)},n:function(){var r=t.next();return a=r.done,r},e:function(r){u=!0,o=r},f:function(){try{a||null==t.return||t.return()}finally{if(u)throw o}}};if(Array.isArray(r)||(t=function(r,a){{var t;if(r)return"string"==typeof r?_arrayLikeToArray(r,a):"Map"===(t="Object"===(t={}.toString.call(r).slice(8,-1))&&r.constructor?r.constructor.name:t)||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0}}(r))||e&&r&&"number"==typeof r.length)return t&&(r=t),n=0,{s:e=function(){},n:function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]}},e:function(r){throw r},f:e};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.ArchiveFormat=_exports.ArchiveCompression=_exports.Archive=void 0;function isObject(val){return"object"==typeof val&&null!==val||"function"==typeof val}var proxyMarker=Symbol("Comlink.proxy"),createEndpoint=Symbol("Comlink.endpoint"),releaseProxy=Symbol("Comlink.releaseProxy"),finalizer=Symbol("Comlink.finalizer"),throwMarker=Symbol("Comlink.thrown"),transferHandlers=new Map([["proxy",{canHandle:function(val){return isObject(val)&&val[proxyMarker]},serialize:function(obj){var _MessageChannel=new MessageChannel,port1=_MessageChannel.port1,_MessageChannel=_MessageChannel.port2;return function expose(obj){var ep=1<arguments.length&&void 0!==arguments[1]?arguments[1]:globalThis;var allowedOrigins=2<arguments.length&&void 0!==arguments[2]?arguments[2]:["*"];ep.addEventListener("message",function callback(ev){if(ev&&ev.data)if(isAllowedOrigin(allowedOrigins,ev.origin)){var returnValue,_Object$assign=Object.assign({path:[]},ev.data),id=_Object$assign.id,type=_Object$assign.type,path=_Object$assign.path,argumentList=(ev.data.argumentList||[]).map(fromWireValue);try{var parent=path.slice(0,-1).reduce(function(obj,prop){return obj[prop]},obj),rawValue=path.reduce(function(obj,prop){return obj[prop]},obj);switch(type){case"GET":returnValue=rawValue;break;case"SET":parent[path.slice(-1)[0]]=fromWireValue(ev.data.value),returnValue=!0;break;case"APPLY":returnValue=rawValue.apply(parent,argumentList);break;case"CONSTRUCT":var value=babelHelpers.construct(rawValue,babelHelpers.toConsumableArray(argumentList));returnValue=proxy(value);break;case"ENDPOINT":var _MessageChannel2=new MessageChannel,port1=_MessageChannel2.port1,port2=_MessageChannel2.port2;expose(obj,port2),returnValue=transfer(port1,[port1]);break;case"RELEASE":returnValue=void 0;break;default:return}}catch(value){returnValue=babelHelpers.defineProperty({value:value},throwMarker,0)}Promise.resolve(returnValue).catch(function(value){return babelHelpers.defineProperty({value:value},throwMarker,0)}).then(function(returnValue){var returnValue=toWireValue(returnValue),returnValue=babelHelpers.slicedToArray(returnValue,2),wireValue=returnValue[0],returnValue=returnValue[1];ep.postMessage(Object.assign(Object.assign({},wireValue),{id:id}),returnValue),"RELEASE"===type&&(ep.removeEventListener("message",callback),closeEndPoint(ep),finalizer in obj)&&"function"==typeof obj[finalizer]&&obj[finalizer]()}).catch(function(error){var _toWireValue3=toWireValue(babelHelpers.defineProperty({value:new TypeError("Unserializable return value")},throwMarker,0)),_toWireValue3=babelHelpers.slicedToArray(_toWireValue3,2),wireValue=_toWireValue3[0],_toWireValue3=_toWireValue3[1];ep.postMessage(Object.assign(Object.assign({},wireValue),{id:id}),_toWireValue3)})}else console.warn("Invalid origin '".concat(ev.origin,"' for comlink proxy"))});ep.start&&ep.start()}(obj,port1),[_MessageChannel,[_MessageChannel]]},deserialize:function(port){return port.start(),wrap(port)}}],["throw",{canHandle:function(value){return isObject(value)&&throwMarker in value},serialize:function(_ref){_ref=_ref.value,_ref=_ref instanceof Error?{isError:!0,value:{message:_ref.message,name:_ref.name,stack:_ref.stack}}:{isError:!1,value:_ref};return[_ref,[]]},deserialize:function(serialized){if(serialized.isError)throw Object.assign(new Error(serialized.value.message),serialized.value);throw serialized.value}}]]);function isAllowedOrigin(allowedOrigins,origin){var _step,_iterator=_createForOfIteratorHelper(allowedOrigins);try{for(_iterator.s();!(_step=_iterator.n()).done;){var allowedOrigin=_step.value;if(origin===allowedOrigin||"*"===allowedOrigin)return!0;if(allowedOrigin instanceof RegExp&&allowedOrigin.test(origin))return!0}}catch(err){_iterator.e(err)}finally{_iterator.f()}return!1}function closeEndPoint(endpoint){"MessagePort"===endpoint.constructor.name&&endpoint.close()}function wrap(ep,target){var pendingListeners=new Map;return ep.addEventListener("message",function(ev){ev=ev.data;if(ev&&ev.id){var resolver=pendingListeners.get(ev.id);if(resolver)try{resolver(ev)}finally{pendingListeners.delete(ev.id)}}}),function createProxy(ep,pendingListeners){var path=2<arguments.length&&void 0!==arguments[2]?arguments[2]:[];var target=3<arguments.length&&void 0!==arguments[3]?arguments[3]:function(){};var isProxyReleased=!1;var proxy=new Proxy(target,{get:function(_target,prop){var r;return throwIfProxyReleased(isProxyReleased),prop===releaseProxy?function(){unregisterProxy(proxy),releaseEndpoint(ep),pendingListeners.clear(),isProxyReleased=!0}:"then"===prop?0===path.length?{then:function(){return proxy}}:(r=requestResponseMessage(ep,pendingListeners,{type:"GET",path:path.map(function(p){return p.toString()})}).then(fromWireValue)).then.bind(r):createProxy(ep,pendingListeners,[].concat(babelHelpers.toConsumableArray(path),[prop]))},set:function(_target,prop,rawValue){throwIfProxyReleased(isProxyReleased);var rawValue=toWireValue(rawValue),rawValue=babelHelpers.slicedToArray(rawValue,2),value=rawValue[0],rawValue=rawValue[1];return requestResponseMessage(ep,pendingListeners,{type:"SET",path:[].concat(babelHelpers.toConsumableArray(path),[prop]).map(function(p){return p.toString()}),value:value},rawValue).then(fromWireValue)},apply:function(_target,_thisArg,rawArgumentList){throwIfProxyReleased(isProxyReleased);var last=path[path.length-1];return last===createEndpoint?requestResponseMessage(ep,pendingListeners,{type:"ENDPOINT"}).then(fromWireValue):"bind"===last?createProxy(ep,pendingListeners,path.slice(0,-1)):(last=processArguments(rawArgumentList),rawArgumentList=babelHelpers.slicedToArray(last,2),last=rawArgumentList[0],rawArgumentList=rawArgumentList[1],requestResponseMessage(ep,pendingListeners,{type:"APPLY",path:path.map(function(p){return p.toString()}),argumentList:last},rawArgumentList).then(fromWireValue))},construct:function(_target,rawArgumentList){throwIfProxyReleased(isProxyReleased);var rawArgumentList=processArguments(rawArgumentList),rawArgumentList=babelHelpers.slicedToArray(rawArgumentList,2),argumentList=rawArgumentList[0],rawArgumentList=rawArgumentList[1];return requestResponseMessage(ep,pendingListeners,{type:"CONSTRUCT",path:path.map(function(p){return p.toString()}),argumentList:argumentList},rawArgumentList).then(fromWireValue)}});registerProxy(proxy,ep);return proxy}(ep,pendingListeners,[],target)}function throwIfProxyReleased(isReleased){if(isReleased)throw new Error("Proxy has been released and is not useable")}function releaseEndpoint(ep){return requestResponseMessage(ep,new Map,{type:"RELEASE"}).then(function(){closeEndPoint(ep)})}var proxyCounter=new WeakMap,proxyFinalizers="FinalizationRegistry"in globalThis&&new FinalizationRegistry(function(ep){var newCount=(proxyCounter.get(ep)||0)-1;proxyCounter.set(ep,newCount),0==newCount&&releaseEndpoint(ep)});function registerProxy(proxy,ep){var newCount=(proxyCounter.get(ep)||0)+1;proxyCounter.set(ep,newCount),proxyFinalizers&&proxyFinalizers.register(proxy,ep,proxy)}function unregisterProxy(proxy){proxyFinalizers&&proxyFinalizers.unregister(proxy)}function processArguments(argumentList){var argumentList=argumentList.map(toWireValue);return[argumentList.map(function(v){return v[0]}),(argumentList=argumentList.map(function(v){return v[1]}),Array.prototype.concat.apply([],argumentList))]}var transferCache=new WeakMap;function transfer(obj,transfers){return transferCache.set(obj,transfers),obj}function proxy(obj){return Object.assign(obj,babelHelpers.defineProperty({},proxyMarker,!0))}function toWireValue(value){var _step2,_iterator2=_createForOfIteratorHelper(transferHandlers);try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var _handler$serialize,_handler$serialize2,_step2$value=babelHelpers.slicedToArray(_step2.value,2),name=_step2$value[0],handler=_step2$value[1];if(handler.canHandle(value))return _handler$serialize=handler.serialize(value),[{type:"HANDLER",name:name,value:(_handler$serialize2=babelHelpers.slicedToArray(_handler$serialize,2))[0]},_handler$serialize2[1]]}}catch(err){_iterator2.e(err)}finally{_iterator2.f()}return[{type:"RAW",value:value},transferCache.get(value)||[]]}function fromWireValue(value){switch(value.type){case"HANDLER":return transferHandlers.get(value.name).deserialize(value.value);case"RAW":return value.value}}function requestResponseMessage(ep,pendingListeners,msg,transfers){return new Promise(function(resolve){var id=new Array(4).fill(0).map(function(){return Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)}).join("-");pendingListeners.set(id,resolve),ep.start&&ep.start(),ep.postMessage(Object.assign({id:id},msg),transfers)})}var CompressedFile=function(){return babelHelpers.createClass(function CompressedFile(name,size,path,lastModified,archiveRef){babelHelpers.classCallCheck(this,CompressedFile),this._name=name,this._size=size,this._path=path,this._lastModified=lastModified,this._archiveRef=archiveRef},[{key:"name",get:function(){return this._name}},{key:"size",get:function(){return this._size}},{key:"lastModified",get:function(){return this._lastModified}},{key:"extract",value:function(){return this._archiveRef.extractSingleFile(this._path)}}])}();function cloneContent(obj){if(obj instanceof File||obj instanceof CompressedFile||null===obj)return obj;for(var o={},_i=0,_Object$keys=Object.keys(obj);_i<_Object$keys.length;_i++){var prop=_Object$keys[_i];o[prop]=cloneContent(obj[prop])}return o}function getObjectPropReference(obj,path){var _step3,path=path.split("/"),cur=(""===path[path.length-1]&&path.pop(),obj),prev=null,_iterator3=_createForOfIteratorHelper(path);try{for(_iterator3.s();!(_step3=_iterator3.n()).done;){var part=_step3.value;cur[part]=cur[part]||{},cur=(prev=cur)[part]}}catch(err){_iterator3.e(err)}finally{_iterator3.f()}return[prev,path[path.length-1]]}var ArchiveReader=function(){return babelHelpers.createClass(function ArchiveReader(file,client,worker){babelHelpers.classCallCheck(this,ArchiveReader),this._content={},this._processed=0,this.file=file,this.client=client,this.worker=worker},[{key:"open",value:function(){var _this=this;return this._content={},this._processed=0,new Promise(function(resolve,_){_this.client.open(_this.file,proxy(function(){resolve(_this)}))})}},{key:"close",value:async function(){var _a;null!=(_a=this.worker)&&_a.terminate(),this.worker=null,this.client=null,this.file=null}},{key:"hasEncryptedData",value:async function(){return this.client.hasEncryptedData()}},{key:"usePassword",value:async function(archivePassword){await this.client.usePassword(archivePassword)}},{key:"setLocale",value:async function(locale){await this.client.setLocale(locale)}},{key:"getFilesObject",value:async function(){var _this2=this;return 0<this._processed?Promise.resolve().then(function(){return _this2._content}):((await this.client.listFiles()).forEach(function(entry){var _getObjectPropReferen=getObjectPropReference(_this2._content,entry.path),_getObjectPropReferen=babelHelpers.slicedToArray(_getObjectPropReferen,2),target=_getObjectPropReferen[0],_getObjectPropReferen=_getObjectPropReferen[1];"FILE"===entry.type&&(target[_getObjectPropReferen]=new CompressedFile(entry.fileName,entry.size,entry.path,entry.lastModified,_this2))}),this._processed=1,cloneContent(this._content))}},{key:"getFilesArray",value:function(){return this.getFilesObject().then(function(obj){return function objectToArray(obj,argument_1){for(var path=1<arguments.length&&void 0!==argument_1?argument_1:"",files=[],_i2=0,_Object$keys2=Object.keys(obj);_i2<_Object$keys2.length;_i2++){var key=_Object$keys2[_i2];obj[key]instanceof File||obj[key]instanceof CompressedFile||null===obj[key]?files.push({file:obj[key]||key,path:path}):files.push.apply(files,babelHelpers.toConsumableArray(objectToArray(obj[key],"".concat(path).concat(key,"/"))))}return files}(obj)})}},{key:"extractSingleFile",value:async function(target){if(null===this.worker)throw new Error("Archive already closed");target=await this.client.extractSingleFile(target);return new File([target.fileData],target.fileName,{type:"application/octet-stream",lastModified:target.lastModified/1e6})}},{key:"extractFiles",value:async function(){var _a,_this3=this,extractCallback=0<arguments.length&&void 0!==arguments[0]?arguments[0]:void 0;return 1<this._processed?Promise.resolve().then(function(){return _this3._content}):((await this.client.extractFiles()).forEach(function(entry){var _getObjectPropReferen3=getObjectPropReference(_this3._content,entry.path),_getObjectPropReferen3=babelHelpers.slicedToArray(_getObjectPropReferen3,2),target=_getObjectPropReferen3[0],_getObjectPropReferen3=_getObjectPropReferen3[1];"FILE"===entry.type&&(target[_getObjectPropReferen3]=new File([entry.fileData],entry.fileName,{type:"application/octet-stream"}),void 0!==extractCallback)&&setTimeout(extractCallback.bind(null,{file:target[_getObjectPropReferen3],path:entry.path}))}),this._processed=2,null!=(_a=this.worker)&&_a.terminate(),cloneContent(this._content))}}])}();!function(ArchiveFormat){ArchiveFormat.SEVEN_ZIP="7zip",ArchiveFormat.AR="ar",ArchiveFormat.ARBSD="arbsd",ArchiveFormat.ARGNU="argnu",ArchiveFormat.ARSVR4="arsvr4",ArchiveFormat.BIN="bin",ArchiveFormat.BSDTAR="bsdtar",ArchiveFormat.CD9660="cd9660",ArchiveFormat.CPIO="cpio",ArchiveFormat.GNUTAR="gnutar",ArchiveFormat.ISO="iso",ArchiveFormat.ISO9660="iso9660",ArchiveFormat.MTREE="mtree",ArchiveFormat.MTREE_CLASSIC="mtree-classic",ArchiveFormat.NEWC="newc",ArchiveFormat.ODC="odc",ArchiveFormat.OLDTAR="oldtar",ArchiveFormat.PAX="pax",ArchiveFormat.PAXR="paxr",ArchiveFormat.POSIX="posix",ArchiveFormat.PWB="pwb",ArchiveFormat.RAW="raw",ArchiveFormat.RPAX="rpax",ArchiveFormat.SHAR="shar",ArchiveFormat.SHARDUMP="shardump",ArchiveFormat.USTAR="ustar",ArchiveFormat.V7TAR="v7tar",ArchiveFormat.V7="v7",ArchiveFormat.WARC="warc",ArchiveFormat.XAR="xar",ArchiveFormat.ZIP="zip"}(_exports.ArchiveFormat={}),function(ArchiveCompression){ArchiveCompression.B64ENCODE="b64encode",ArchiveCompression.BZIP2="bzip2",ArchiveCompression.COMPRESS="compress",ArchiveCompression.GRZIP="grzip",ArchiveCompression.GZIP="gzip",ArchiveCompression.LRZIP="lrzip",ArchiveCompression.LZ4="lz4",ArchiveCompression.LZIP="lzip",ArchiveCompression.LZMA="lzma",ArchiveCompression.LZOP="lzop",ArchiveCompression.UUENCODE="uuencode",ArchiveCompression.XZ="xz",ArchiveCompression.ZSTD="zstd",ArchiveCompression.NONE="none"}(_exports.ArchiveCompression={}),(_exports.Archive=function(){function Archive(){babelHelpers.classCallCheck(this,Archive)}return babelHelpers.createClass(Archive,null,[{key:"init",value:function(){return Archive._options=(0<arguments.length&&void 0!==arguments[0]?arguments[0]:null)||{}}},{key:"open",value:async function(file){var worker=Archive.getWorker(Archive._options),client=await Archive.getClient(worker,Archive._options);return new ArchiveReader(file,client,worker).open()}},{key:"write",value:async function(_ref3){var files=_ref3.files,outputFileName=_ref3.outputFileName,compression=_ref3.compression,format=_ref3.format,_ref3=_ref3.passphrase,_ref3=void 0===_ref3?null:_ref3,worker=Archive.getWorker(Archive._options),files=await(await Archive.getClient(worker,Archive._options)).writeArchive(files,compression,format,_ref3);return worker.terminate(),new File([files],outputFileName,{type:"application/octet-stream"})}},{key:"getWorker",value:function(options){return options.getWorker?options.getWorker():new Worker(options.workerUrl||new URL("./worker-bundle.js",import1.meta.url),{type:"module"})}},{key:"getClient",value:async function(worker,options){var _a=(null==(_a=options.createClient)?void 0:_a.call(options,worker))||wrap(worker),options=Promise.withResolvers(),worker=options.promise,resolve=options.resolve,options=await new _a(proxy(function(){resolve()}));return await worker,options}}])}())._options={},Promise.withResolvers||(Promise.withResolvers=function(){var a,b,c=new this(function(resolve,reject){a=resolve,b=reject});return{resolve:a,reject:b,promise:c}})}); |