@webexatech/plugin-collection-transfer 0.1.2 → 0.1.3-nocobase.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- (()=>{var e={794:(e,r,t)=>{var n=t(300).Buffer;var i=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117];if(typeof Int32Array!=="undefined"){i=new Int32Array(i)}function ensureBuffer(e){if(n.isBuffer(e)){return e}var r=typeof n.alloc==="function"&&typeof n.from==="function";if(typeof e==="number"){return r?n.alloc(e):new n(e)}else if(typeof e==="string"){return r?n.from(e):new n(e)}else{throw new Error("input must be buffer, number, or string, received "+typeof e)}}function bufferizeInt(e){var r=ensureBuffer(4);r.writeInt32BE(e,0);return r}function _crc32(e,r){e=ensureBuffer(e);if(n.isBuffer(r)){r=r.readUInt32BE(0)}var t=~~r^-1;for(var o=0;o<e.length;o++){t=i[(t^e[o])&255]^t>>>8}return t^-1}function crc32(){return bufferizeInt(_crc32.apply(null,arguments))}crc32.signed=function(){return _crc32.apply(null,arguments)};crc32.unsigned=function(){return _crc32.apply(null,arguments)>>>0};e.exports=crc32},833:e=>{e.exports=Pend;function Pend(){this.pending=0;this.max=Infinity;this.listeners=[];this.waiting=[];this.error=null}Pend.prototype.go=function(e){if(this.pending<this.max){pendGo(this,e)}else{this.waiting.push(e)}};Pend.prototype.wait=function(e){if(this.pending===0){e(this.error)}else{this.listeners.push(e)}};Pend.prototype.hold=function(){return pendHold(this)};function pendHold(e){e.pending+=1;var r=false;return onCb;function onCb(t){if(r)throw new Error("callback called twice");r=true;e.error=e.error||t;e.pending-=1;if(e.waiting.length>0&&e.pending<e.max){pendGo(e,e.waiting.shift())}else if(e.pending===0){var n=e.listeners;e.listeners=[];n.forEach(cbListener)}}function cbListener(r){r(e.error)}}function pendGo(e,r){r(pendHold(e))}},276:(e,r,t)=>{var n=t(147);var i=t(837);var o=t(955);var a=o.Readable;var s=o.Writable;var f=o.PassThrough;var l=t(833);var d=t(361).EventEmitter;r.createFromBuffer=createFromBuffer;r.createFromFd=createFromFd;r.BufferSlicer=BufferSlicer;r.FdSlicer=FdSlicer;i.inherits(FdSlicer,d);function FdSlicer(e,r){r=r||{};d.call(this);this.fd=e;this.pend=new l;this.pend.max=1;this.refCount=0;this.autoClose=!!r.autoClose}FdSlicer.prototype.read=function(e,r,t,i,o){var a=this;a.pend.go((function(s){n.read(a.fd,e,r,t,i,(function(e,r,t){s();o(e,r,t)}))}))};FdSlicer.prototype.write=function(e,r,t,i,o){var a=this;a.pend.go((function(s){n.write(a.fd,e,r,t,i,(function(e,r,t){s();o(e,r,t)}))}))};FdSlicer.prototype.createReadStream=function(e){return new ReadStream(this,e)};FdSlicer.prototype.createWriteStream=function(e){return new WriteStream(this,e)};FdSlicer.prototype.ref=function(){this.refCount+=1};FdSlicer.prototype.unref=function(){var e=this;e.refCount-=1;if(e.refCount>0)return;if(e.refCount<0)throw new Error("invalid unref");if(e.autoClose){n.close(e.fd,onCloseDone)}function onCloseDone(r){if(r){e.emit("error",r)}else{e.emit("close")}}};i.inherits(ReadStream,a);function ReadStream(e,r){r=r||{};a.call(this,r);this.context=e;this.context.ref();this.start=r.start||0;this.endOffset=r.end;this.pos=this.start;this.destroyed=false}ReadStream.prototype._read=function(e){var r=this;if(r.destroyed)return;var t=Math.min(r._readableState.highWaterMark,e);if(r.endOffset!=null){t=Math.min(t,r.endOffset-r.pos)}if(t<=0){r.destroyed=true;r.push(null);r.context.unref();return}r.context.pend.go((function(e){if(r.destroyed)return e();var i=Buffer.allocUnsafe(t);n.read(r.context.fd,i,0,t,r.pos,(function(t,n){if(t){r.destroy(t)}else if(n===0){r.destroyed=true;r.push(null);r.context.unref()}else{r.pos+=n;r.push(i.slice(0,n))}e()}))}))};ReadStream.prototype.destroy=function(e){if(this.destroyed)return;e=e||new Error("stream destroyed");this.destroyed=true;this.emit("error",e);this.context.unref()};i.inherits(WriteStream,s);function WriteStream(e,r){r=r||{};s.call(this,r);this.context=e;this.context.ref();this.start=r.start||0;this.endOffset=r.end==null?Infinity:+r.end;this.bytesWritten=0;this.pos=this.start;this.destroyed=false;this.on("finish",this.destroy.bind(this))}WriteStream.prototype._write=function(e,r,t){var i=this;if(i.destroyed)return;if(i.pos+e.length>i.endOffset){var o=new Error("maximum file length exceeded");o.code="ETOOBIG";i.destroy();t(o);return}i.context.pend.go((function(r){if(i.destroyed)return r();n.write(i.context.fd,e,0,e.length,i.pos,(function(e,n){if(e){i.destroy();r();t(e)}else{i.bytesWritten+=n;i.pos+=n;i.emit("progress");r();t()}}))}))};WriteStream.prototype.destroy=function(){if(this.destroyed)return;this.destroyed=true;this.context.unref()};i.inherits(BufferSlicer,d);function BufferSlicer(e,r){d.call(this);r=r||{};this.refCount=0;this.buffer=e;this.maxChunkSize=r.maxChunkSize||Number.MAX_SAFE_INTEGER}BufferSlicer.prototype.read=function(e,r,t,n,i){if(!(0<=r&&r<=e.length))throw new RangeError("offset outside buffer: 0 <= "+r+" <= "+e.length);if(n<0)throw new RangeError("position is negative: "+n);if(r+t>e.length){t=e.length-r}if(n+t>this.buffer.length){t=this.buffer.length-n}if(t<=0){setImmediate((function(){i(null,0)}));return}this.buffer.copy(e,r,n,n+t);setImmediate((function(){i(null,t)}))};BufferSlicer.prototype.write=function(e,r,t,n,i){e.copy(this.buffer,n,r,r+t);setImmediate((function(){i(null,t,e)}))};BufferSlicer.prototype.createReadStream=function(e){e=e||{};var r=new f(e);r.destroyed=false;r.start=e.start||0;r.endOffset=e.end;r.pos=r.endOffset||this.buffer.length;var t=this.buffer.slice(r.start,r.pos);var n=0;while(true){var i=n+this.maxChunkSize;if(i>=t.length){if(n<t.length){r.write(t.slice(n,t.length))}break}r.write(t.slice(n,i));n=i}r.end();r.destroy=function(){r.destroyed=true};return r};BufferSlicer.prototype.createWriteStream=function(e){var r=this;e=e||{};var t=new s(e);t.start=e.start||0;t.endOffset=e.end==null?this.buffer.length:+e.end;t.bytesWritten=0;t.pos=t.start;t.destroyed=false;t._write=function(e,n,i){if(t.destroyed)return;var o=t.pos+e.length;if(o>t.endOffset){var a=new Error("maximum file length exceeded");a.code="ETOOBIG";t.destroyed=true;i(a);return}e.copy(r.buffer,t.pos,0,e.length);t.bytesWritten+=e.length;t.pos=o;t.emit("progress");i()};t.destroy=function(){t.destroyed=true};return t};BufferSlicer.prototype.ref=function(){this.refCount+=1};BufferSlicer.prototype.unref=function(){this.refCount-=1;if(this.refCount<0){throw new Error("invalid unref")}};function createFromBuffer(e,r){return new BufferSlicer(e,r)}function createFromFd(e,r){return new FdSlicer(e,r)}},300:e=>{"use strict";e.exports=require("buffer")},361:e=>{"use strict";e.exports=require("events")},147:e=>{"use strict";e.exports=require("fs")},955:e=>{"use strict";e.exports=require("stream")},837:e=>{"use strict";e.exports=require("util")},796:e=>{"use strict";e.exports=require("zlib")}};var r={};function __nccwpck_require__(t){var n=r[t];if(n!==undefined){return n.exports}var i=r[t]={exports:{}};var o=true;try{e[t](i,i.exports,__nccwpck_require__);o=false}finally{if(o)delete r[t]}return i.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t={};(()=>{var e=t;var r=__nccwpck_require__(147);var n=__nccwpck_require__(796);var i=__nccwpck_require__(276);var o=__nccwpck_require__(794);var a=__nccwpck_require__(837);var s=__nccwpck_require__(361).EventEmitter;var f=__nccwpck_require__(955).Transform;var l=__nccwpck_require__(955).PassThrough;var d=__nccwpck_require__(955).Writable;e.open=open;e.fromFd=fromFd;e.fromBuffer=fromBuffer;e.fromRandomAccessReader=fromRandomAccessReader;e.dosDateTimeToDate=dosDateTimeToDate;e.getFileNameLowLevel=getFileNameLowLevel;e.validateFileName=validateFileName;e.parseExtraFields=parseExtraFields;e.ZipFile=ZipFile;e.Entry=Entry;e.LocalFileHeader=LocalFileHeader;e.RandomAccessReader=RandomAccessReader;function open(e,t,n){if(typeof t==="function"){n=t;t=null}if(t==null)t={};if(t.autoClose==null)t.autoClose=true;if(t.lazyEntries==null)t.lazyEntries=false;if(t.decodeStrings==null)t.decodeStrings=true;if(t.validateEntrySizes==null)t.validateEntrySizes=true;if(t.strictFileNames==null)t.strictFileNames=false;if(n==null)n=defaultCallback;r.open(e,"r",(function(e,i){if(e)return n(e);fromFd(i,t,(function(e,t){if(e)r.close(i,defaultCallback);n(e,t)}))}))}function fromFd(e,t,n){if(typeof t==="function"){n=t;t=null}if(t==null)t={};if(t.autoClose==null)t.autoClose=false;if(t.lazyEntries==null)t.lazyEntries=false;if(t.decodeStrings==null)t.decodeStrings=true;if(t.validateEntrySizes==null)t.validateEntrySizes=true;if(t.strictFileNames==null)t.strictFileNames=false;if(n==null)n=defaultCallback;r.fstat(e,(function(r,o){if(r)return n(r);var a=i.createFromFd(e,{autoClose:true});fromRandomAccessReader(a,o.size,t,n)}))}function fromBuffer(e,r,t){if(typeof r==="function"){t=r;r=null}if(r==null)r={};r.autoClose=false;if(r.lazyEntries==null)r.lazyEntries=false;if(r.decodeStrings==null)r.decodeStrings=true;if(r.validateEntrySizes==null)r.validateEntrySizes=true;if(r.strictFileNames==null)r.strictFileNames=false;var n=i.createFromBuffer(e,{maxChunkSize:65536});fromRandomAccessReader(n,e.length,r,t)}function fromRandomAccessReader(e,r,t,n){if(typeof t==="function"){n=t;t=null}if(t==null)t={};if(t.autoClose==null)t.autoClose=true;if(t.lazyEntries==null)t.lazyEntries=false;if(t.decodeStrings==null)t.decodeStrings=true;var i=!!t.decodeStrings;if(t.validateEntrySizes==null)t.validateEntrySizes=true;if(t.strictFileNames==null)t.strictFileNames=false;if(n==null)n=defaultCallback;if(typeof r!=="number")throw new Error("expected totalSize parameter to be a number");if(r>Number.MAX_SAFE_INTEGER){throw new Error("zip file too large. only file sizes up to 2^52 are supported due to JavaScript's Number type being an IEEE 754 double.")}e.ref();var o=22;var a=20;var s=65535;var f=Math.min(a+o+s,r);var l=c(f);var d=r-l.length;readAndAssertNoEof(e,l,0,f,d,(function(s){if(s)return n(s);for(var d=f-o;d>=0;d-=1){if(l.readUInt32LE(d)!==101010256)continue;var u=l.subarray(d);var p=u.readUInt16LE(4);var m=u.readUInt16LE(10);var h=u.readUInt32LE(16);var y=u.readUInt16LE(20);var E=u.length-o;if(y!==E){return n(new Error("Invalid comment length. Expected: "+E+". Found: "+y+". Are there extra bytes at the end of the file? Or is the end of central dir signature `PK☺☻` in the comment?"))}var v=i?decodeBuffer(u.subarray(22),false):u.subarray(22);if(d-a>=0&&l.readUInt32LE(d-a)===117853008){var w=l.subarray(d-a,d-a+a);var g=readUInt64LE(w,8);var F=c(56);return readAndAssertNoEof(e,F,0,F.length,g,(function(o){if(o)return n(o);if(F.readUInt32LE(0)!==101075792){return n(new Error("invalid zip64 end of central directory record signature"))}p=F.readUInt32LE(16);if(p!==0){return n(new Error("multi-disk zip files are not supported: found disk number: "+p))}m=readUInt64LE(F,32);h=readUInt64LE(F,48);return n(null,new ZipFile(e,h,r,m,v,t.autoClose,t.lazyEntries,i,t.validateEntrySizes,t.strictFileNames))}))}if(p!==0){return n(new Error("multi-disk zip files are not supported: found disk number: "+p))}return n(null,new ZipFile(e,h,r,m,v,t.autoClose,t.lazyEntries,i,t.validateEntrySizes,t.strictFileNames))}n(new Error("End of central directory record signature not found. Either not a zip file, or file is truncated."))}))}a.inherits(ZipFile,s);function ZipFile(e,r,t,n,i,o,a,f,l,d){var u=this;s.call(u);u.reader=e;u.reader.on("error",(function(e){emitError(u,e)}));u.reader.once("close",(function(){u.emit("close")}));u.readEntryCursor=r;u.fileSize=t;u.entryCount=n;u.comment=i;u.entriesRead=0;u.autoClose=!!o;u.lazyEntries=!!a;u.decodeStrings=!!f;u.validateEntrySizes=!!l;u.strictFileNames=!!d;u.isOpen=true;u.emittedError=false;if(!u.lazyEntries)u._readEntry()}ZipFile.prototype.close=function(){if(!this.isOpen)return;this.isOpen=false;this.reader.unref()};function emitErrorAndAutoClose(e,r){if(e.autoClose)e.close();emitError(e,r)}function emitError(e,r){if(e.emittedError)return;e.emittedError=true;e.emit("error",r)}ZipFile.prototype.readEntry=function(){if(!this.lazyEntries)throw new Error("readEntry() called without lazyEntries:true");this._readEntry()};ZipFile.prototype._readEntry=function(){var e=this;if(e.entryCount===e.entriesRead){setImmediate((function(){if(e.autoClose)e.close();if(e.emittedError)return;e.emit("end")}));return}if(e.emittedError)return;var r=c(46);readAndAssertNoEof(e.reader,r,0,r.length,e.readEntryCursor,(function(t){if(t)return emitErrorAndAutoClose(e,t);if(e.emittedError)return;var n=new Entry;var i=r.readUInt32LE(0);if(i!==33639248)return emitErrorAndAutoClose(e,new Error("invalid central directory file header signature: 0x"+i.toString(16)));n.versionMadeBy=r.readUInt16LE(4);n.versionNeededToExtract=r.readUInt16LE(6);n.generalPurposeBitFlag=r.readUInt16LE(8);n.compressionMethod=r.readUInt16LE(10);n.lastModFileTime=r.readUInt16LE(12);n.lastModFileDate=r.readUInt16LE(14);n.crc32=r.readUInt32LE(16);n.compressedSize=r.readUInt32LE(20);n.uncompressedSize=r.readUInt32LE(24);n.fileNameLength=r.readUInt16LE(28);n.extraFieldLength=r.readUInt16LE(30);n.fileCommentLength=r.readUInt16LE(32);n.internalFileAttributes=r.readUInt16LE(36);n.externalFileAttributes=r.readUInt32LE(38);n.relativeOffsetOfLocalHeader=r.readUInt32LE(42);if(n.generalPurposeBitFlag&64)return emitErrorAndAutoClose(e,new Error("strong encryption is not supported"));e.readEntryCursor+=46;r=c(n.fileNameLength+n.extraFieldLength+n.fileCommentLength);readAndAssertNoEof(e.reader,r,0,r.length,e.readEntryCursor,(function(t){if(t)return emitErrorAndAutoClose(e,t);if(e.emittedError)return;n.fileNameRaw=r.subarray(0,n.fileNameLength);var i=n.fileNameLength+n.extraFieldLength;n.extraFieldRaw=r.subarray(n.fileNameLength,i);n.fileCommentRaw=r.subarray(i,i+n.fileCommentLength);try{n.extraFields=parseExtraFields(n.extraFieldRaw)}catch(t){return emitErrorAndAutoClose(e,t)}if(e.decodeStrings){var o=(n.generalPurposeBitFlag&2048)!==0;n.fileComment=decodeBuffer(n.fileCommentRaw,o);n.fileName=getFileNameLowLevel(n.generalPurposeBitFlag,n.fileNameRaw,n.extraFields,e.strictFileNames);var a=validateFileName(n.fileName);if(a!=null)return emitErrorAndAutoClose(e,new Error(a))}else{n.fileComment=n.fileCommentRaw;n.fileName=n.fileNameRaw}n.comment=n.fileComment;e.readEntryCursor+=r.length;e.entriesRead+=1;for(var s=0;s<n.extraFields.length;s++){var f=n.extraFields[s];if(f.id!==1)continue;var l=f.data;var d=0;if(n.uncompressedSize===4294967295){if(d+8>l.length){return emitErrorAndAutoClose(e,new Error("zip64 extended information extra field does not include uncompressed size"))}n.uncompressedSize=readUInt64LE(l,d);d+=8}if(n.compressedSize===4294967295){if(d+8>l.length){return emitErrorAndAutoClose(e,new Error("zip64 extended information extra field does not include compressed size"))}n.compressedSize=readUInt64LE(l,d);d+=8}if(n.relativeOffsetOfLocalHeader===4294967295){if(d+8>l.length){return emitErrorAndAutoClose(e,new Error("zip64 extended information extra field does not include relative header offset"))}n.relativeOffsetOfLocalHeader=readUInt64LE(l,d);d+=8}break}if(e.validateEntrySizes&&n.compressionMethod===0){var u=n.uncompressedSize;if(n.isEncrypted()){u+=12}if(n.compressedSize!==u){var c="compressed/uncompressed size mismatch for stored file: "+n.compressedSize+" != "+n.uncompressedSize;return emitErrorAndAutoClose(e,new Error(c))}}e.emit("entry",n);if(!e.lazyEntries)e._readEntry()}))}))};ZipFile.prototype.openReadStream=function(e,r,t){var n=this;var i=0;var o=e.compressedSize;if(t==null){t=r;r=null}if(r==null){r={}}else{if(r.decodeFileData===false){if(r.decrypt!=null){throw new Error("cannot use options.decrypt when options.decodeFileData === false")}if(r.decompress!=null){throw new Error("cannot use options.decompress when options.decodeFileData === false")}}else{if(r.decrypt!=null){if(!e.isEncrypted()){throw new Error("options.decrypt can only be specified for encrypted entries. See also option decodeFileData.")}if(r.decrypt!==false)throw new Error("invalid options.decrypt value: "+r.decrypt);if(e.isCompressed()){if(r.decompress!==false)throw new Error("entry is encrypted and compressed, and options.decompress !== false. See also option decodeFileData.")}}if(r.decompress!=null){if(!e.isCompressed()){throw new Error("options.decompress can only be specified for compressed entries. See also option decodeFileData.")}if(!(r.decompress===false||r.decompress===true)){throw new Error("invalid options.decompress value: "+r.decompress)}s=r.decompress}}if(r.start!=null){i=r.start;if(i<0)throw new Error("options.start < 0");if(i>e.compressedSize)throw new Error("options.start > entry.compressedSize")}if(r.end!=null){o=r.end;if(o<0)throw new Error("options.end < 0");if(o>e.compressedSize)throw new Error("options.end > entry.compressedSize");if(o<i)throw new Error("options.end < options.start")}}var a=r.decodeFileData===false||(e.compressionMethod===0||e.compressionMethod===8&&r.decompress===false)&&(!e.isEncrypted()||r.decrypt===false);if(r.start!=null||r.end!=null){if(!a)throw new Error("start/end range require options.decodeFileData === false for non-trivial encoded entries.")}if(!n.isOpen)return t(new Error("closed"));if(e.isEncrypted()&&!a){if(r.decrypt!==false)return t(new Error("entry is encrypted, and options.decodeFileData !== false"))}var s;if(a){s=false}else if(e.compressionMethod===8){s=r.decodeFileData!==true}else{return t(new Error("unsupported compression method: "+e.compressionMethod))}n.readLocalFileHeader(e,{minimal:true},(function(r,a){if(r)return t(r);n.openReadStreamLowLevel(a.fileDataStart,e.compressedSize,i,o,s,e.uncompressedSize,t)}))};ZipFile.prototype.openReadStreamLowLevel=function(e,r,t,i,o,a,s){var f=this;var l=e+r;var d=f.reader.createReadStream({start:e+t,end:e+i});var u=d;if(o){var c=false;var p=n.createInflateRaw();d.on("error",(function(e){setImmediate((function(){if(!c)p.emit("error",e)}))}));d.pipe(p);if(f.validateEntrySizes){u=new AssertByteCountStream(a);p.on("error",(function(e){setImmediate((function(){if(!c)u.emit("error",e)}))}));p.pipe(u)}else{u=p}installDestroyFn(u,(function(){c=true;if(p!==u)p.unpipe(u);d.unpipe(p);d.destroy()}))}s(null,u)};ZipFile.prototype.readLocalFileHeader=function(e,r,t){var n=this;if(t==null){t=r;r=null}if(r==null)r={};n.reader.ref();var i=c(30);readAndAssertNoEof(n.reader,i,0,i.length,e.relativeOffsetOfLocalHeader,(function(o){try{if(o)return t(o);var a=i.readUInt32LE(0);if(a!==67324752){return t(new Error("invalid local file header signature: 0x"+a.toString(16)))}var s=i.readUInt16LE(26);var f=i.readUInt16LE(28);var l=e.relativeOffsetOfLocalHeader+30+s+f;if(l+e.compressedSize>n.fileSize){return t(new Error("file data overflows file bounds: "+l+" + "+e.compressedSize+" > "+n.fileSize))}if(r.minimal){return t(null,{fileDataStart:l})}var d=new LocalFileHeader;d.fileDataStart=l;d.versionNeededToExtract=i.readUInt16LE(4);d.generalPurposeBitFlag=i.readUInt16LE(6);d.compressionMethod=i.readUInt16LE(8);d.lastModFileTime=i.readUInt16LE(10);d.lastModFileDate=i.readUInt16LE(12);d.crc32=i.readUInt32LE(14);d.compressedSize=i.readUInt32LE(18);d.uncompressedSize=i.readUInt32LE(22);d.fileNameLength=s;d.extraFieldLength=f;i=c(s+f);n.reader.ref();readAndAssertNoEof(n.reader,i,0,i.length,e.relativeOffsetOfLocalHeader+30,(function(e){try{if(e)return t(e);d.fileName=i.subarray(0,s);d.extraField=i.subarray(s);return t(null,d)}finally{n.reader.unref()}}))}finally{n.reader.unref()}}))};function Entry(){}Entry.prototype.getLastModDate=function(e){if(e==null)e={};if(!e.forceDosFormat){for(var r=0;r<this.extraFields.length;r++){var t=this.extraFields[r];if(t.id===21589){var n=t.data;if(n.length<5)continue;var i=n[0];var o=1;if(!(i&o))continue;var a=n.readInt32LE(1);return new Date(a*1e3)}else if(t.id===10){var n=t.data;if(n.length!==32)continue;if(n.readUInt16LE(4)!==1)continue;if(n.readUInt16LE(6)!==24)continue;var s=n.readUInt32LE(8)+4294967296*n.readInt32LE(12);var f=s/1e4-116444736e5;return new Date(f)}}}return dosDateTimeToDate(this.lastModFileDate,this.lastModFileTime,e.timezone)};Entry.prototype.canDecodeFileData=function(){return!this.isEncrypted()&&(this.compressionMethod===0||this.compressionMethod===8)};Entry.prototype.isEncrypted=function(){return(this.generalPurposeBitFlag&1)!==0};Entry.prototype.isCompressed=function(){return this.compressionMethod===8};function LocalFileHeader(){}function dosDateTimeToDate(e,r,t){var n=e&31;var i=(e>>5&15)-1;var o=(e>>9&127)+1980;var a=0;var s=(r&31)*2;var f=r>>5&63;var l=r>>11&31;if(t==null||t==="local"){return new Date(o,i,n,l,f,s,a)}else if(t==="UTC"){return new Date(Date.UTC(o,i,n,l,f,s,a))}else{throw new Error("unrecognized options.timezone: "+options.timezone)}}function getFileNameLowLevel(e,r,t,n){var i=null;for(var a=0;a<t.length;a++){var s=t[a];if(s.id===28789){if(s.data.length<6){continue}if(s.data.readUInt8(0)!==1){continue}var f=s.data.readUInt32LE(1);if(o.unsigned(r)!==f){continue}i=decodeBuffer(s.data.subarray(5),true);break}}if(i==null){var l=(e&2048)!==0;i=decodeBuffer(r,l)}if(!n){i=i.replace(/\\/g,"/")}return i}function validateFileName(e){if(e.indexOf("\\")!==-1){return"invalid characters in fileName: "+e}if(/^[a-zA-Z]:/.test(e)||/^\//.test(e)){return"absolute path: "+e}if(e.split("/").indexOf("..")!==-1){return"invalid relative path: "+e}return null}function parseExtraFields(e){var r=[];var t=0;while(t<e.length-3){var n=e.readUInt16LE(t+0);var i=e.readUInt16LE(t+2);var o=t+4;var a=o+i;if(a>e.length)throw new Error("extra field length exceeds extra field buffer size");var s=e.subarray(o,a);r.push({id:n,data:s});t=a}return r}function readAndAssertNoEof(e,r,t,n,i,o){if(n===0){return setImmediate((function(){o(null,c(0))}))}e.read(r,t,n,i,(function(e,r){if(e)return o(e);if(r<n){return o(new Error("unexpected EOF"))}o()}))}a.inherits(AssertByteCountStream,f);function AssertByteCountStream(e){f.call(this);this.actualByteCount=0;this.expectedByteCount=e}AssertByteCountStream.prototype._transform=function(e,r,t){this.actualByteCount+=e.length;if(this.actualByteCount>this.expectedByteCount){var n="too many bytes in the stream. expected "+this.expectedByteCount+". got at least "+this.actualByteCount;return t(new Error(n))}t(null,e)};AssertByteCountStream.prototype._flush=function(e){if(this.actualByteCount<this.expectedByteCount){var r="not enough bytes in the stream. expected "+this.expectedByteCount+". got only "+this.actualByteCount;return e(new Error(r))}e()};a.inherits(RandomAccessReader,s);function RandomAccessReader(){s.call(this);this.refCount=0}RandomAccessReader.prototype.ref=function(){this.refCount+=1};RandomAccessReader.prototype.unref=function(){var e=this;e.refCount-=1;if(e.refCount>0)return;if(e.refCount<0)throw new Error("invalid unref");e.close(onCloseDone);function onCloseDone(r){if(r)return e.emit("error",r);e.emit("close")}};RandomAccessReader.prototype.createReadStream=function(e){if(e==null)e={};var r=e.start;var t=e.end;if(r===t){var n=new l;setImmediate((function(){n.end()}));return n}var i=this._readStreamForRange(r,t);var o=false;var a=new RefUnrefFilter(this);i.on("error",(function(e){setImmediate((function(){if(!o)a.emit("error",e)}))}));installDestroyFn(a,(function(){i.unpipe(a);a.unref();i.destroy()}));var s=new AssertByteCountStream(t-r);a.on("error",(function(e){setImmediate((function(){if(!o)s.emit("error",e)}))}));installDestroyFn(s,(function(){o=true;a.unpipe(s);a.destroy()}));return i.pipe(a).pipe(s)};RandomAccessReader.prototype._readStreamForRange=function(e,r){throw new Error("not implemented")};RandomAccessReader.prototype.read=function(e,r,t,n,i){var o=this.createReadStream({start:n,end:n+t});var a=new d;var s=0;a._write=function(t,n,i){t.copy(e,r+s,0,t.length);s+=t.length;i()};a.on("finish",i);o.on("error",(function(e){i(e)}));o.pipe(a)};RandomAccessReader.prototype.close=function(e){setImmediate(e)};a.inherits(RefUnrefFilter,l);function RefUnrefFilter(e){l.call(this);this.context=e;this.context.ref();this.unreffedYet=false}RefUnrefFilter.prototype._flush=function(e){this.unref();e()};RefUnrefFilter.prototype.unref=function(e){if(this.unreffedYet)return;this.unreffedYet=true;this.context.unref()};var u="\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ";function decodeBuffer(e,r){if(r){return e.toString("utf8")}else{var t="";for(var n=0;n<e.length;n++){t+=u[e[n]]}return t}}function readUInt64LE(e,r){var t=e.readUInt32LE(r);var n=e.readUInt32LE(r+4);return n*4294967296+t}var c;if(typeof Buffer.allocUnsafe==="function"){c=function(e){return Buffer.allocUnsafe(e)}}else{c=function(e){return new Buffer(e)}}function installDestroyFn(e,r){if(typeof e.destroy==="function"){e._destroy=function(e,t){r();if(t!=null)t(e)}}else{e.destroy=r}}function defaultCallback(e){if(e)throw e}})();module.exports=t})();
1
+ (()=>{var e={794:(e,r,t)=>{var n=t(300).Buffer;var i=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117];if(typeof Int32Array!=="undefined"){i=new Int32Array(i)}function ensureBuffer(e){if(n.isBuffer(e)){return e}var r=typeof n.alloc==="function"&&typeof n.from==="function";if(typeof e==="number"){return r?n.alloc(e):new n(e)}else if(typeof e==="string"){return r?n.from(e):new n(e)}else{throw new Error("input must be buffer, number, or string, received "+typeof e)}}function bufferizeInt(e){var r=ensureBuffer(4);r.writeInt32BE(e,0);return r}function _crc32(e,r){e=ensureBuffer(e);if(n.isBuffer(r)){r=r.readUInt32BE(0)}var t=~~r^-1;for(var o=0;o<e.length;o++){t=i[(t^e[o])&255]^t>>>8}return t^-1}function crc32(){return bufferizeInt(_crc32.apply(null,arguments))}crc32.signed=function(){return _crc32.apply(null,arguments)};crc32.unsigned=function(){return _crc32.apply(null,arguments)>>>0};e.exports=crc32},10:(e,r,t)=>{var n=t(147);var i=t(837);var o=t(955);var s=o.Readable;var a=o.Writable;var f=o.PassThrough;var d=t(833);var u=t(361).EventEmitter;r.createFromBuffer=createFromBuffer;r.createFromFd=createFromFd;r.BufferSlicer=BufferSlicer;r.FdSlicer=FdSlicer;i.inherits(FdSlicer,u);function FdSlicer(e,r){r=r||{};u.call(this);this.fd=e;this.pend=new d;this.pend.max=1;this.refCount=0;this.autoClose=!!r.autoClose}FdSlicer.prototype.read=function(e,r,t,i,o){var s=this;s.pend.go((function(a){n.read(s.fd,e,r,t,i,(function(e,r,t){a();o(e,r,t)}))}))};FdSlicer.prototype.write=function(e,r,t,i,o){var s=this;s.pend.go((function(a){n.write(s.fd,e,r,t,i,(function(e,r,t){a();o(e,r,t)}))}))};FdSlicer.prototype.createReadStream=function(e){return new ReadStream(this,e)};FdSlicer.prototype.createWriteStream=function(e){return new WriteStream(this,e)};FdSlicer.prototype.ref=function(){this.refCount+=1};FdSlicer.prototype.unref=function(){var e=this;e.refCount-=1;if(e.refCount>0)return;if(e.refCount<0)throw new Error("invalid unref");if(e.autoClose){n.close(e.fd,onCloseDone)}function onCloseDone(r){if(r){e.emit("error",r)}else{e.emit("close")}}};i.inherits(ReadStream,s);function ReadStream(e,r){r=r||{};s.call(this,r);this.context=e;this.context.ref();this.start=r.start||0;this.endOffset=r.end;this.pos=this.start;this.destroyed=false}ReadStream.prototype._read=function(e){var r=this;if(r.destroyed)return;var t=Math.min(r._readableState.highWaterMark,e);if(r.endOffset!=null){t=Math.min(t,r.endOffset-r.pos)}if(t<=0){r.destroyed=true;r.push(null);r.context.unref();return}r.context.pend.go((function(e){if(r.destroyed)return e();var i=new Buffer(t);n.read(r.context.fd,i,0,t,r.pos,(function(t,n){if(t){r.destroy(t)}else if(n===0){r.destroyed=true;r.push(null);r.context.unref()}else{r.pos+=n;r.push(i.slice(0,n))}e()}))}))};ReadStream.prototype.destroy=function(e){if(this.destroyed)return;e=e||new Error("stream destroyed");this.destroyed=true;this.emit("error",e);this.context.unref()};i.inherits(WriteStream,a);function WriteStream(e,r){r=r||{};a.call(this,r);this.context=e;this.context.ref();this.start=r.start||0;this.endOffset=r.end==null?Infinity:+r.end;this.bytesWritten=0;this.pos=this.start;this.destroyed=false;this.on("finish",this.destroy.bind(this))}WriteStream.prototype._write=function(e,r,t){var i=this;if(i.destroyed)return;if(i.pos+e.length>i.endOffset){var o=new Error("maximum file length exceeded");o.code="ETOOBIG";i.destroy();t(o);return}i.context.pend.go((function(r){if(i.destroyed)return r();n.write(i.context.fd,e,0,e.length,i.pos,(function(e,n){if(e){i.destroy();r();t(e)}else{i.bytesWritten+=n;i.pos+=n;i.emit("progress");r();t()}}))}))};WriteStream.prototype.destroy=function(){if(this.destroyed)return;this.destroyed=true;this.context.unref()};i.inherits(BufferSlicer,u);function BufferSlicer(e,r){u.call(this);r=r||{};this.refCount=0;this.buffer=e;this.maxChunkSize=r.maxChunkSize||Number.MAX_SAFE_INTEGER}BufferSlicer.prototype.read=function(e,r,t,n,i){var o=n+t;var s=o-this.buffer.length;var a=s>0?s:t;this.buffer.copy(e,r,n,o);setImmediate((function(){i(null,a)}))};BufferSlicer.prototype.write=function(e,r,t,n,i){e.copy(this.buffer,n,r,r+t);setImmediate((function(){i(null,t,e)}))};BufferSlicer.prototype.createReadStream=function(e){e=e||{};var r=new f(e);r.destroyed=false;r.start=e.start||0;r.endOffset=e.end;r.pos=r.endOffset||this.buffer.length;var t=this.buffer.slice(r.start,r.pos);var n=0;while(true){var i=n+this.maxChunkSize;if(i>=t.length){if(n<t.length){r.write(t.slice(n,t.length))}break}r.write(t.slice(n,i));n=i}r.end();r.destroy=function(){r.destroyed=true};return r};BufferSlicer.prototype.createWriteStream=function(e){var r=this;e=e||{};var t=new a(e);t.start=e.start||0;t.endOffset=e.end==null?this.buffer.length:+e.end;t.bytesWritten=0;t.pos=t.start;t.destroyed=false;t._write=function(e,n,i){if(t.destroyed)return;var o=t.pos+e.length;if(o>t.endOffset){var s=new Error("maximum file length exceeded");s.code="ETOOBIG";t.destroyed=true;i(s);return}e.copy(r.buffer,t.pos,0,e.length);t.bytesWritten+=e.length;t.pos=o;t.emit("progress");i()};t.destroy=function(){t.destroyed=true};return t};BufferSlicer.prototype.ref=function(){this.refCount+=1};BufferSlicer.prototype.unref=function(){this.refCount-=1;if(this.refCount<0){throw new Error("invalid unref")}};function createFromBuffer(e,r){return new BufferSlicer(e,r)}function createFromFd(e,r){return new FdSlicer(e,r)}},833:e=>{e.exports=Pend;function Pend(){this.pending=0;this.max=Infinity;this.listeners=[];this.waiting=[];this.error=null}Pend.prototype.go=function(e){if(this.pending<this.max){pendGo(this,e)}else{this.waiting.push(e)}};Pend.prototype.wait=function(e){if(this.pending===0){e(this.error)}else{this.listeners.push(e)}};Pend.prototype.hold=function(){return pendHold(this)};function pendHold(e){e.pending+=1;var r=false;return onCb;function onCb(t){if(r)throw new Error("callback called twice");r=true;e.error=e.error||t;e.pending-=1;if(e.waiting.length>0&&e.pending<e.max){pendGo(e,e.waiting.shift())}else if(e.pending===0){var n=e.listeners;e.listeners=[];n.forEach(cbListener)}}function cbListener(r){r(e.error)}}function pendGo(e,r){r(pendHold(e))}},300:e=>{"use strict";e.exports=require("buffer")},361:e=>{"use strict";e.exports=require("events")},147:e=>{"use strict";e.exports=require("fs")},955:e=>{"use strict";e.exports=require("stream")},837:e=>{"use strict";e.exports=require("util")},796:e=>{"use strict";e.exports=require("zlib")}};var r={};function __nccwpck_require__(t){var n=r[t];if(n!==undefined){return n.exports}var i=r[t]={exports:{}};var o=true;try{e[t](i,i.exports,__nccwpck_require__);o=false}finally{if(o)delete r[t]}return i.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t={};(()=>{var e=t;var r=__nccwpck_require__(147);var n=__nccwpck_require__(796);var i=__nccwpck_require__(10);var o=__nccwpck_require__(794);var s=__nccwpck_require__(837);var a=__nccwpck_require__(361).EventEmitter;var f=__nccwpck_require__(955).Transform;var d=__nccwpck_require__(955).PassThrough;var u=__nccwpck_require__(955).Writable;e.open=open;e.fromFd=fromFd;e.fromBuffer=fromBuffer;e.fromRandomAccessReader=fromRandomAccessReader;e.dosDateTimeToDate=dosDateTimeToDate;e.validateFileName=validateFileName;e.ZipFile=ZipFile;e.Entry=Entry;e.RandomAccessReader=RandomAccessReader;function open(e,t,n){if(typeof t==="function"){n=t;t=null}if(t==null)t={};if(t.autoClose==null)t.autoClose=true;if(t.lazyEntries==null)t.lazyEntries=false;if(t.decodeStrings==null)t.decodeStrings=true;if(t.validateEntrySizes==null)t.validateEntrySizes=true;if(t.strictFileNames==null)t.strictFileNames=false;if(n==null)n=defaultCallback;r.open(e,"r",(function(e,i){if(e)return n(e);fromFd(i,t,(function(e,t){if(e)r.close(i,defaultCallback);n(e,t)}))}))}function fromFd(e,t,n){if(typeof t==="function"){n=t;t=null}if(t==null)t={};if(t.autoClose==null)t.autoClose=false;if(t.lazyEntries==null)t.lazyEntries=false;if(t.decodeStrings==null)t.decodeStrings=true;if(t.validateEntrySizes==null)t.validateEntrySizes=true;if(t.strictFileNames==null)t.strictFileNames=false;if(n==null)n=defaultCallback;r.fstat(e,(function(r,o){if(r)return n(r);var s=i.createFromFd(e,{autoClose:true});fromRandomAccessReader(s,o.size,t,n)}))}function fromBuffer(e,r,t){if(typeof r==="function"){t=r;r=null}if(r==null)r={};r.autoClose=false;if(r.lazyEntries==null)r.lazyEntries=false;if(r.decodeStrings==null)r.decodeStrings=true;if(r.validateEntrySizes==null)r.validateEntrySizes=true;if(r.strictFileNames==null)r.strictFileNames=false;var n=i.createFromBuffer(e,{maxChunkSize:65536});fromRandomAccessReader(n,e.length,r,t)}function fromRandomAccessReader(e,r,t,n){if(typeof t==="function"){n=t;t=null}if(t==null)t={};if(t.autoClose==null)t.autoClose=true;if(t.lazyEntries==null)t.lazyEntries=false;if(t.decodeStrings==null)t.decodeStrings=true;var i=!!t.decodeStrings;if(t.validateEntrySizes==null)t.validateEntrySizes=true;if(t.strictFileNames==null)t.strictFileNames=false;if(n==null)n=defaultCallback;if(typeof r!=="number")throw new Error("expected totalSize parameter to be a number");if(r>Number.MAX_SAFE_INTEGER){throw new Error("zip file too large. only file sizes up to 2^52 are supported due to JavaScript's Number type being an IEEE 754 double.")}e.ref();var o=22;var s=65535;var a=Math.min(o+s,r);var f=c(a);var d=r-f.length;readAndAssertNoEof(e,f,0,a,d,(function(s){if(s)return n(s);for(var u=a-o;u>=0;u-=1){if(f.readUInt32LE(u)!==101010256)continue;var l=f.slice(u);var p=l.readUInt16LE(4);if(p!==0){return n(new Error("multi-disk zip files are not supported: found disk number: "+p))}var m=l.readUInt16LE(10);var h=l.readUInt32LE(16);var y=l.readUInt16LE(20);var v=l.length-o;if(y!==v){return n(new Error("invalid comment length. expected: "+v+". found: "+y))}var E=i?decodeBuffer(l,22,l.length,false):l.slice(22);if(!(m===65535||h===4294967295)){return n(null,new ZipFile(e,h,r,m,E,t.autoClose,t.lazyEntries,i,t.validateEntrySizes,t.strictFileNames))}var w=c(20);var g=d+u-w.length;readAndAssertNoEof(e,w,0,w.length,g,(function(o){if(o)return n(o);if(w.readUInt32LE(0)!==117853008){return n(new Error("invalid zip64 end of central directory locator signature"))}var s=readUInt64LE(w,8);var a=c(56);readAndAssertNoEof(e,a,0,a.length,s,(function(o){if(o)return n(o);if(a.readUInt32LE(0)!==101075792){return n(new Error("invalid zip64 end of central directory record signature"))}m=readUInt64LE(a,32);h=readUInt64LE(a,48);return n(null,new ZipFile(e,h,r,m,E,t.autoClose,t.lazyEntries,i,t.validateEntrySizes,t.strictFileNames))}))}));return}n(new Error("end of central directory record signature not found"))}))}s.inherits(ZipFile,a);function ZipFile(e,r,t,n,i,o,s,f,d,u){var l=this;a.call(l);l.reader=e;l.reader.on("error",(function(e){emitError(l,e)}));l.reader.once("close",(function(){l.emit("close")}));l.readEntryCursor=r;l.fileSize=t;l.entryCount=n;l.comment=i;l.entriesRead=0;l.autoClose=!!o;l.lazyEntries=!!s;l.decodeStrings=!!f;l.validateEntrySizes=!!d;l.strictFileNames=!!u;l.isOpen=true;l.emittedError=false;if(!l.lazyEntries)l._readEntry()}ZipFile.prototype.close=function(){if(!this.isOpen)return;this.isOpen=false;this.reader.unref()};function emitErrorAndAutoClose(e,r){if(e.autoClose)e.close();emitError(e,r)}function emitError(e,r){if(e.emittedError)return;e.emittedError=true;e.emit("error",r)}ZipFile.prototype.readEntry=function(){if(!this.lazyEntries)throw new Error("readEntry() called without lazyEntries:true");this._readEntry()};ZipFile.prototype._readEntry=function(){var e=this;if(e.entryCount===e.entriesRead){setImmediate((function(){if(e.autoClose)e.close();if(e.emittedError)return;e.emit("end")}));return}if(e.emittedError)return;var r=c(46);readAndAssertNoEof(e.reader,r,0,r.length,e.readEntryCursor,(function(t){if(t)return emitErrorAndAutoClose(e,t);if(e.emittedError)return;var n=new Entry;var i=r.readUInt32LE(0);if(i!==33639248)return emitErrorAndAutoClose(e,new Error("invalid central directory file header signature: 0x"+i.toString(16)));n.versionMadeBy=r.readUInt16LE(4);n.versionNeededToExtract=r.readUInt16LE(6);n.generalPurposeBitFlag=r.readUInt16LE(8);n.compressionMethod=r.readUInt16LE(10);n.lastModFileTime=r.readUInt16LE(12);n.lastModFileDate=r.readUInt16LE(14);n.crc32=r.readUInt32LE(16);n.compressedSize=r.readUInt32LE(20);n.uncompressedSize=r.readUInt32LE(24);n.fileNameLength=r.readUInt16LE(28);n.extraFieldLength=r.readUInt16LE(30);n.fileCommentLength=r.readUInt16LE(32);n.internalFileAttributes=r.readUInt16LE(36);n.externalFileAttributes=r.readUInt32LE(38);n.relativeOffsetOfLocalHeader=r.readUInt32LE(42);if(n.generalPurposeBitFlag&64)return emitErrorAndAutoClose(e,new Error("strong encryption is not supported"));e.readEntryCursor+=46;r=c(n.fileNameLength+n.extraFieldLength+n.fileCommentLength);readAndAssertNoEof(e.reader,r,0,r.length,e.readEntryCursor,(function(t){if(t)return emitErrorAndAutoClose(e,t);if(e.emittedError)return;var i=(n.generalPurposeBitFlag&2048)!==0;n.fileName=e.decodeStrings?decodeBuffer(r,0,n.fileNameLength,i):r.slice(0,n.fileNameLength);var s=n.fileNameLength+n.extraFieldLength;var a=r.slice(n.fileNameLength,s);n.extraFields=[];var f=0;while(f<a.length-3){var d=a.readUInt16LE(f+0);var u=a.readUInt16LE(f+2);var l=f+4;var p=l+u;if(p>a.length)return emitErrorAndAutoClose(e,new Error("extra field length exceeds extra field buffer size"));var m=c(u);a.copy(m,0,l,p);n.extraFields.push({id:d,data:m});f=p}n.fileComment=e.decodeStrings?decodeBuffer(r,s,s+n.fileCommentLength,i):r.slice(s,s+n.fileCommentLength);n.comment=n.fileComment;e.readEntryCursor+=r.length;e.entriesRead+=1;if(n.uncompressedSize===4294967295||n.compressedSize===4294967295||n.relativeOffsetOfLocalHeader===4294967295){var h=null;for(var f=0;f<n.extraFields.length;f++){var y=n.extraFields[f];if(y.id===1){h=y.data;break}}if(h==null){return emitErrorAndAutoClose(e,new Error("expected zip64 extended information extra field"))}var v=0;if(n.uncompressedSize===4294967295){if(v+8>h.length){return emitErrorAndAutoClose(e,new Error("zip64 extended information extra field does not include uncompressed size"))}n.uncompressedSize=readUInt64LE(h,v);v+=8}if(n.compressedSize===4294967295){if(v+8>h.length){return emitErrorAndAutoClose(e,new Error("zip64 extended information extra field does not include compressed size"))}n.compressedSize=readUInt64LE(h,v);v+=8}if(n.relativeOffsetOfLocalHeader===4294967295){if(v+8>h.length){return emitErrorAndAutoClose(e,new Error("zip64 extended information extra field does not include relative header offset"))}n.relativeOffsetOfLocalHeader=readUInt64LE(h,v);v+=8}}if(e.decodeStrings){for(var f=0;f<n.extraFields.length;f++){var y=n.extraFields[f];if(y.id===28789){if(y.data.length<6){continue}if(y.data.readUInt8(0)!==1){continue}var E=y.data.readUInt32LE(1);if(o.unsigned(r.slice(0,n.fileNameLength))!==E){continue}n.fileName=decodeBuffer(y.data,5,y.data.length,true);break}}}if(e.validateEntrySizes&&n.compressionMethod===0){var w=n.uncompressedSize;if(n.isEncrypted()){w+=12}if(n.compressedSize!==w){var g="compressed/uncompressed size mismatch for stored file: "+n.compressedSize+" != "+n.uncompressedSize;return emitErrorAndAutoClose(e,new Error(g))}}if(e.decodeStrings){if(!e.strictFileNames){n.fileName=n.fileName.replace(/\\/g,"/")}var S=validateFileName(n.fileName,e.validateFileNameOptions);if(S!=null)return emitErrorAndAutoClose(e,new Error(S))}e.emit("entry",n);if(!e.lazyEntries)e._readEntry()}))}))};ZipFile.prototype.openReadStream=function(e,r,t){var i=this;var o=0;var s=e.compressedSize;if(t==null){t=r;r={}}else{if(r.decrypt!=null){if(!e.isEncrypted()){throw new Error("options.decrypt can only be specified for encrypted entries")}if(r.decrypt!==false)throw new Error("invalid options.decrypt value: "+r.decrypt);if(e.isCompressed()){if(r.decompress!==false)throw new Error("entry is encrypted and compressed, and options.decompress !== false")}}if(r.decompress!=null){if(!e.isCompressed()){throw new Error("options.decompress can only be specified for compressed entries")}if(!(r.decompress===false||r.decompress===true)){throw new Error("invalid options.decompress value: "+r.decompress)}}if(r.start!=null||r.end!=null){if(e.isCompressed()&&r.decompress!==false){throw new Error("start/end range not allowed for compressed entry without options.decompress === false")}if(e.isEncrypted()&&r.decrypt!==false){throw new Error("start/end range not allowed for encrypted entry without options.decrypt === false")}}if(r.start!=null){o=r.start;if(o<0)throw new Error("options.start < 0");if(o>e.compressedSize)throw new Error("options.start > entry.compressedSize")}if(r.end!=null){s=r.end;if(s<0)throw new Error("options.end < 0");if(s>e.compressedSize)throw new Error("options.end > entry.compressedSize");if(s<o)throw new Error("options.end < options.start")}}if(!i.isOpen)return t(new Error("closed"));if(e.isEncrypted()){if(r.decrypt!==false)return t(new Error("entry is encrypted, and options.decrypt !== false"))}i.reader.ref();var a=c(30);readAndAssertNoEof(i.reader,a,0,a.length,e.relativeOffsetOfLocalHeader,(function(f){try{if(f)return t(f);var d=a.readUInt32LE(0);if(d!==67324752){return t(new Error("invalid local file header signature: 0x"+d.toString(16)))}var u=a.readUInt16LE(26);var l=a.readUInt16LE(28);var c=e.relativeOffsetOfLocalHeader+a.length+u+l;var p;if(e.compressionMethod===0){p=false}else if(e.compressionMethod===8){p=r.decompress!=null?r.decompress:true}else{return t(new Error("unsupported compression method: "+e.compressionMethod))}var m=c;var h=m+e.compressedSize;if(e.compressedSize!==0){if(h>i.fileSize){return t(new Error("file data overflows file bounds: "+m+" + "+e.compressedSize+" > "+i.fileSize))}}var y=i.reader.createReadStream({start:m+o,end:m+s});var v=y;if(p){var E=false;var w=n.createInflateRaw();y.on("error",(function(e){setImmediate((function(){if(!E)w.emit("error",e)}))}));y.pipe(w);if(i.validateEntrySizes){v=new AssertByteCountStream(e.uncompressedSize);w.on("error",(function(e){setImmediate((function(){if(!E)v.emit("error",e)}))}));w.pipe(v)}else{v=w}v.destroy=function(){E=true;if(w!==v)w.unpipe(v);y.unpipe(w);y.destroy()}}t(null,v)}finally{i.reader.unref()}}))};function Entry(){}Entry.prototype.getLastModDate=function(){return dosDateTimeToDate(this.lastModFileDate,this.lastModFileTime)};Entry.prototype.isEncrypted=function(){return(this.generalPurposeBitFlag&1)!==0};Entry.prototype.isCompressed=function(){return this.compressionMethod===8};function dosDateTimeToDate(e,r){var t=e&31;var n=(e>>5&15)-1;var i=(e>>9&127)+1980;var o=0;var s=(r&31)*2;var a=r>>5&63;var f=r>>11&31;return new Date(i,n,t,f,a,s,o)}function validateFileName(e){if(e.indexOf("\\")!==-1){return"invalid characters in fileName: "+e}if(/^[a-zA-Z]:/.test(e)||/^\//.test(e)){return"absolute path: "+e}if(e.split("/").indexOf("..")!==-1){return"invalid relative path: "+e}return null}function readAndAssertNoEof(e,r,t,n,i,o){if(n===0){return setImmediate((function(){o(null,c(0))}))}e.read(r,t,n,i,(function(e,r){if(e)return o(e);if(r<n){return o(new Error("unexpected EOF"))}o()}))}s.inherits(AssertByteCountStream,f);function AssertByteCountStream(e){f.call(this);this.actualByteCount=0;this.expectedByteCount=e}AssertByteCountStream.prototype._transform=function(e,r,t){this.actualByteCount+=e.length;if(this.actualByteCount>this.expectedByteCount){var n="too many bytes in the stream. expected "+this.expectedByteCount+". got at least "+this.actualByteCount;return t(new Error(n))}t(null,e)};AssertByteCountStream.prototype._flush=function(e){if(this.actualByteCount<this.expectedByteCount){var r="not enough bytes in the stream. expected "+this.expectedByteCount+". got only "+this.actualByteCount;return e(new Error(r))}e()};s.inherits(RandomAccessReader,a);function RandomAccessReader(){a.call(this);this.refCount=0}RandomAccessReader.prototype.ref=function(){this.refCount+=1};RandomAccessReader.prototype.unref=function(){var e=this;e.refCount-=1;if(e.refCount>0)return;if(e.refCount<0)throw new Error("invalid unref");e.close(onCloseDone);function onCloseDone(r){if(r)return e.emit("error",r);e.emit("close")}};RandomAccessReader.prototype.createReadStream=function(e){var r=e.start;var t=e.end;if(r===t){var n=new d;setImmediate((function(){n.end()}));return n}var i=this._readStreamForRange(r,t);var o=false;var s=new RefUnrefFilter(this);i.on("error",(function(e){setImmediate((function(){if(!o)s.emit("error",e)}))}));s.destroy=function(){i.unpipe(s);s.unref();i.destroy()};var a=new AssertByteCountStream(t-r);s.on("error",(function(e){setImmediate((function(){if(!o)a.emit("error",e)}))}));a.destroy=function(){o=true;s.unpipe(a);s.destroy()};return i.pipe(s).pipe(a)};RandomAccessReader.prototype._readStreamForRange=function(e,r){throw new Error("not implemented")};RandomAccessReader.prototype.read=function(e,r,t,n,i){var o=this.createReadStream({start:n,end:n+t});var s=new u;var a=0;s._write=function(t,n,i){t.copy(e,r+a,0,t.length);a+=t.length;i()};s.on("finish",i);o.on("error",(function(e){i(e)}));o.pipe(s)};RandomAccessReader.prototype.close=function(e){setImmediate(e)};s.inherits(RefUnrefFilter,d);function RefUnrefFilter(e){d.call(this);this.context=e;this.context.ref();this.unreffedYet=false}RefUnrefFilter.prototype._flush=function(e){this.unref();e()};RefUnrefFilter.prototype.unref=function(e){if(this.unreffedYet)return;this.unreffedYet=true;this.context.unref()};var l="\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ";function decodeBuffer(e,r,t,n){if(n){return e.toString("utf8",r,t)}else{var i="";for(var o=r;o<t;o++){i+=l[e[o]]}return i}}function readUInt64LE(e,r){var t=e.readUInt32LE(r);var n=e.readUInt32LE(r+4);return n*4294967296+t}var c;if(typeof Buffer.allocUnsafe==="function"){c=function(e){return Buffer.allocUnsafe(e)}}else{c=function(e){return new Buffer(e)}}function defaultCallback(e){if(e)throw e}})();module.exports=t})();
@@ -1 +1 @@
1
- {"name":"yauzl","version":"3.3.0","description":"yet another unzip library for node","engines":{"node":">=12"},"main":"index.js","scripts":{"test":"node test/test.js"},"repository":{"type":"git","url":"git+https://github.com/thejoshwolfe/yauzl.git"},"keywords":["unzip","zip","stream","archive","file"],"author":"Josh Wolfe <thejoshwolfe@gmail.com>","license":"MIT","bugs":{"url":"https://github.com/thejoshwolfe/yauzl/issues"},"homepage":"https://github.com/thejoshwolfe/yauzl","dependencies":{"buffer-crc32":"~0.2.3","pend":"~1.2.0"},"devDependencies":{"bl":"^6.0.11"},"files":["fd-slicer.js","index.js"],"_lastModified":"2026-11-22T13:16:02.566Z"}
1
+ {"name":"yauzl","version":"2.10.0","description":"yet another unzip library for node","main":"index.js","scripts":{"test":"node test/test.js","test-cov":"istanbul cover test/test.js","test-travis":"istanbul cover --report lcovonly test/test.js"},"repository":{"type":"git","url":"https://github.com/thejoshwolfe/yauzl.git"},"keywords":["unzip","zip","stream","archive","file"],"author":"Josh Wolfe <thejoshwolfe@gmail.com>","license":"MIT","bugs":{"url":"https://github.com/thejoshwolfe/yauzl/issues"},"homepage":"https://github.com/thejoshwolfe/yauzl","dependencies":{"fd-slicer":"~1.1.0","buffer-crc32":"~0.2.3"},"devDependencies":{"bl":"~1.0.0","istanbul":"~0.3.4","pend":"~1.2.0"},"files":["index.js"],"_lastModified":"2026-11-22T14:30:02.458Z"}
@@ -6,6 +6,8 @@ declare const _default: {
6
6
  actions: {
7
7
  listCollections(ctx: Context, next: Next): Promise<void>;
8
8
  export(ctx: Context, next: Next): Promise<void>;
9
+ /** Streams a file prepared by `export` once, then deletes it. */
10
+ download(ctx: Context, next: Next): Promise<void>;
9
11
  /** Multipart upload of a package; returns what would be created and any blocking problems. No writes. */
10
12
  preview(ctx: Context, next: Next): Promise<void>;
11
13
  import(ctx: Context, next: Next): Promise<void>;
@@ -41,18 +41,37 @@ __export(resourcer_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(resourcer_exports);
43
43
  var import_utils = require("@nocobase/utils");
44
+ var import_crypto = __toESM(require("crypto"));
44
45
  var import_fs = __toESM(require("fs"));
45
46
  var import_promises = __toESM(require("fs/promises"));
46
47
  var import_os = __toESM(require("os"));
48
+ var import_path = __toESM(require("path"));
47
49
  var import_exporter = require("./exporter");
48
50
  var import_importer = require("./importer");
49
51
  var import_package = __toESM(require("../../package.json"));
50
52
  const RESOURCE_NAME = "collectionTransfer";
51
53
  const NS = import_package.default.name;
52
54
  const MAX_UPLOAD_BYTES = 200 * 1024 * 1024;
55
+ const EXPORT_TOKEN = /^[0-9a-f-]{36}$/;
56
+ const EXPORT_TTL_MS = 60 * 60 * 1e3;
53
57
  function errorMessage(error) {
54
58
  return error instanceof Error ? error.message : String(error);
55
59
  }
60
+ function exportsDir() {
61
+ return (0, import_utils.storagePathJoin)("tmp", "collection-transfer-exports");
62
+ }
63
+ async function removeExpiredExports() {
64
+ const root = exportsDir();
65
+ const entries = await import_promises.default.readdir(root).catch(() => []);
66
+ const now = Date.now();
67
+ for (const entry of entries) {
68
+ const entryPath = import_path.default.join(root, entry);
69
+ const stat = await import_promises.default.stat(entryPath).catch(() => null);
70
+ if (stat && now - stat.mtimeMs > EXPORT_TTL_MS) {
71
+ await import_promises.default.rm(entryPath, { recursive: true, force: true });
72
+ }
73
+ }
74
+ }
56
75
  var resourcer_default = {
57
76
  name: RESOURCE_NAME,
58
77
  middleware: async (ctx, next) => {
@@ -78,12 +97,36 @@ var resourcer_default = {
78
97
  } catch (error) {
79
98
  ctx.throw(400, errorMessage(error));
80
99
  }
81
- const stream = import_fs.default.createReadStream(result.filePath);
100
+ await removeExpiredExports();
101
+ const token = import_crypto.default.randomUUID();
102
+ const dir = import_path.default.join(exportsDir(), token);
103
+ await import_promises.default.mkdir(dir, { recursive: true });
104
+ await import_promises.default.rename(result.filePath, import_path.default.join(dir, result.fileName)).catch(async () => {
105
+ await import_promises.default.copyFile(result.filePath, import_path.default.join(dir, result.fileName));
106
+ await import_promises.default.rm(result.filePath, { force: true });
107
+ });
108
+ const { plugins, ...summary } = result.manifest;
109
+ ctx.body = { token, fileName: result.fileName, manifest: summary };
110
+ await next();
111
+ },
112
+ /** Streams a file prepared by `export` once, then deletes it. */
113
+ async download(ctx, next) {
114
+ const { token } = ctx.action.params;
115
+ if (typeof token !== "string" || !EXPORT_TOKEN.test(token)) {
116
+ ctx.throw(400, "Invalid download token");
117
+ }
118
+ const dir = import_path.default.join(exportsDir(), token);
119
+ const claimed = `${dir}.sending-${import_crypto.default.randomUUID()}`;
120
+ const owned = await import_promises.default.rename(dir, claimed).then(() => true).catch(() => false);
121
+ const [fileName] = owned ? await import_promises.default.readdir(claimed).catch(() => []) : [];
122
+ if (!fileName) {
123
+ ctx.throw(404, "Export not found or already downloaded");
124
+ }
125
+ const stream = import_fs.default.createReadStream(import_path.default.join(claimed, fileName));
82
126
  stream.on("close", () => {
83
- import_promises.default.rm(result.filePath, { force: true }).catch((error) => ctx.app.log.warn(error));
127
+ import_promises.default.rm(claimed, { recursive: true, force: true }).catch((error) => ctx.app.log.warn(error));
84
128
  });
85
- ctx.attachment(result.fileName);
86
- ctx.set("X-Collection-Transfer-Manifest", encodeURIComponent(JSON.stringify(result.manifest)));
129
+ ctx.attachment(fileName);
87
130
  ctx.body = stream;
88
131
  await next();
89
132
  },
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "数据表迁移",
5
5
  "description": "Move collections between NocoBase environments: export one or more collections (schema, optionally data) to a file and import it elsewhere, with per-collection conflict handling.",
6
6
  "description.zh-CN": "在 NocoBase 环境之间迁移数据表:将一个或多个数据表(结构,可选包含数据)导出为文件并导入到其他环境,支持逐表冲突处理。",
7
- "version": "0.1.2",
7
+ "version": "0.1.3-nocobase.2.1",
8
8
  "license": "Apache-2.0",
9
9
  "author": "Webexa Technologies LLP",
10
10
  "homepage": "https://github.com/webexatech/plugin-collection-transfer#readme",
@@ -1,314 +0,0 @@
1
- // This was adapted from https://github.com/andrewrk/node-fd-slicer by Andrew Kelley under the MIT License.
2
- var fs = require('fs');
3
- var util = require('util');
4
- var stream = require('stream');
5
- var Readable = stream.Readable;
6
- var Writable = stream.Writable;
7
- var PassThrough = stream.PassThrough;
8
- var Pend = require('pend');
9
- var EventEmitter = require('events').EventEmitter;
10
-
11
- exports.createFromBuffer = createFromBuffer;
12
- exports.createFromFd = createFromFd;
13
- exports.BufferSlicer = BufferSlicer;
14
- exports.FdSlicer = FdSlicer;
15
-
16
- util.inherits(FdSlicer, EventEmitter);
17
- function FdSlicer(fd, options) {
18
- options = options || {};
19
- EventEmitter.call(this);
20
-
21
- this.fd = fd;
22
- this.pend = new Pend();
23
- this.pend.max = 1;
24
- this.refCount = 0;
25
- this.autoClose = !!options.autoClose;
26
- }
27
-
28
- FdSlicer.prototype.read = function(buffer, offset, length, position, callback) {
29
- var self = this;
30
- self.pend.go(function(cb) {
31
- fs.read(self.fd, buffer, offset, length, position, function(err, bytesRead, buffer) {
32
- cb();
33
- callback(err, bytesRead, buffer);
34
- });
35
- });
36
- };
37
-
38
- FdSlicer.prototype.write = function(buffer, offset, length, position, callback) {
39
- var self = this;
40
- self.pend.go(function(cb) {
41
- fs.write(self.fd, buffer, offset, length, position, function(err, written, buffer) {
42
- cb();
43
- callback(err, written, buffer);
44
- });
45
- });
46
- };
47
-
48
- FdSlicer.prototype.createReadStream = function(options) {
49
- return new ReadStream(this, options);
50
- };
51
-
52
- FdSlicer.prototype.createWriteStream = function(options) {
53
- return new WriteStream(this, options);
54
- };
55
-
56
- FdSlicer.prototype.ref = function() {
57
- this.refCount += 1;
58
- };
59
-
60
- FdSlicer.prototype.unref = function() {
61
- var self = this;
62
- self.refCount -= 1;
63
-
64
- if (self.refCount > 0) return;
65
- if (self.refCount < 0) throw new Error("invalid unref");
66
-
67
- if (self.autoClose) {
68
- fs.close(self.fd, onCloseDone);
69
- }
70
-
71
- function onCloseDone(err) {
72
- if (err) {
73
- self.emit('error', err);
74
- } else {
75
- self.emit('close');
76
- }
77
- }
78
- };
79
-
80
- util.inherits(ReadStream, Readable);
81
- function ReadStream(context, options) {
82
- options = options || {};
83
- Readable.call(this, options);
84
-
85
- this.context = context;
86
- this.context.ref();
87
-
88
- this.start = options.start || 0;
89
- this.endOffset = options.end;
90
- this.pos = this.start;
91
- this.destroyed = false;
92
- }
93
-
94
- ReadStream.prototype._read = function(n) {
95
- var self = this;
96
- if (self.destroyed) return;
97
-
98
- var toRead = Math.min(self._readableState.highWaterMark, n);
99
- if (self.endOffset != null) {
100
- toRead = Math.min(toRead, self.endOffset - self.pos);
101
- }
102
- if (toRead <= 0) {
103
- self.destroyed = true;
104
- self.push(null);
105
- self.context.unref();
106
- return;
107
- }
108
- self.context.pend.go(function(cb) {
109
- if (self.destroyed) return cb();
110
- var buffer = Buffer.allocUnsafe(toRead);
111
- fs.read(self.context.fd, buffer, 0, toRead, self.pos, function(err, bytesRead) {
112
- if (err) {
113
- self.destroy(err);
114
- } else if (bytesRead === 0) {
115
- self.destroyed = true;
116
- self.push(null);
117
- self.context.unref();
118
- } else {
119
- self.pos += bytesRead;
120
- self.push(buffer.slice(0, bytesRead));
121
- }
122
- cb();
123
- });
124
- });
125
- };
126
-
127
- ReadStream.prototype.destroy = function(err) {
128
- if (this.destroyed) return;
129
- err = err || new Error("stream destroyed");
130
- this.destroyed = true;
131
- this.emit('error', err);
132
- this.context.unref();
133
- };
134
-
135
- util.inherits(WriteStream, Writable);
136
- function WriteStream(context, options) {
137
- options = options || {};
138
- Writable.call(this, options);
139
-
140
- this.context = context;
141
- this.context.ref();
142
-
143
- this.start = options.start || 0;
144
- this.endOffset = (options.end == null) ? Infinity : +options.end;
145
- this.bytesWritten = 0;
146
- this.pos = this.start;
147
- this.destroyed = false;
148
-
149
- this.on('finish', this.destroy.bind(this));
150
- }
151
-
152
- WriteStream.prototype._write = function(buffer, encoding, callback) {
153
- var self = this;
154
- if (self.destroyed) return;
155
-
156
- if (self.pos + buffer.length > self.endOffset) {
157
- var err = new Error("maximum file length exceeded");
158
- err.code = 'ETOOBIG';
159
- self.destroy();
160
- callback(err);
161
- return;
162
- }
163
- self.context.pend.go(function(cb) {
164
- if (self.destroyed) return cb();
165
- fs.write(self.context.fd, buffer, 0, buffer.length, self.pos, function(err, bytes) {
166
- if (err) {
167
- self.destroy();
168
- cb();
169
- callback(err);
170
- } else {
171
- self.bytesWritten += bytes;
172
- self.pos += bytes;
173
- self.emit('progress');
174
- cb();
175
- callback();
176
- }
177
- });
178
- });
179
- };
180
-
181
- WriteStream.prototype.destroy = function() {
182
- if (this.destroyed) return;
183
- this.destroyed = true;
184
- this.context.unref();
185
- };
186
-
187
- util.inherits(BufferSlicer, EventEmitter);
188
- function BufferSlicer(buffer, options) {
189
- EventEmitter.call(this);
190
-
191
- options = options || {};
192
- this.refCount = 0;
193
- this.buffer = buffer;
194
- this.maxChunkSize = options.maxChunkSize || Number.MAX_SAFE_INTEGER;
195
- }
196
-
197
- BufferSlicer.prototype.read = function(buffer, offset, length, position, callback) {
198
- if (!(0 <= offset && offset <= buffer.length)) throw new RangeError("offset outside buffer: 0 <= " + offset + " <= " + buffer.length);
199
- if (position < 0) throw new RangeError("position is negative: " + position);
200
- if (offset + length > buffer.length) {
201
- // The caller's buffer can't hold all the bytes they're trying to read.
202
- // Clamp the length instead of giving an error.
203
- // The callback will be informed of fewer than expected bytes written.
204
- length = buffer.length - offset;
205
- }
206
- if (position + length > this.buffer.length) {
207
- // Clamp any attempt to read past the end of the source buffer.
208
- length = this.buffer.length - position;
209
- }
210
- if (length <= 0) {
211
- // After any clamping, we're fully out of bounds or otherwise have nothing to do.
212
- // This isn't an error; it's just zero bytes written.
213
- setImmediate(function() {
214
- callback(null, 0);
215
- });
216
- return;
217
- }
218
- this.buffer.copy(buffer, offset, position, position + length);
219
- setImmediate(function() {
220
- callback(null, length);
221
- });
222
- };
223
-
224
- BufferSlicer.prototype.write = function(buffer, offset, length, position, callback) {
225
- buffer.copy(this.buffer, position, offset, offset + length);
226
- setImmediate(function() {
227
- callback(null, length, buffer);
228
- });
229
- };
230
-
231
- BufferSlicer.prototype.createReadStream = function(options) {
232
- options = options || {};
233
- var readStream = new PassThrough(options);
234
- readStream.destroyed = false;
235
- readStream.start = options.start || 0;
236
- readStream.endOffset = options.end;
237
- // by the time this function returns, we'll be done.
238
- readStream.pos = readStream.endOffset || this.buffer.length;
239
-
240
- // respect the maxChunkSize option to slice up the chunk into smaller pieces.
241
- var entireSlice = this.buffer.slice(readStream.start, readStream.pos);
242
- var offset = 0;
243
- while (true) {
244
- var nextOffset = offset + this.maxChunkSize;
245
- if (nextOffset >= entireSlice.length) {
246
- // last chunk
247
- if (offset < entireSlice.length) {
248
- readStream.write(entireSlice.slice(offset, entireSlice.length));
249
- }
250
- break;
251
- }
252
- readStream.write(entireSlice.slice(offset, nextOffset));
253
- offset = nextOffset;
254
- }
255
-
256
- readStream.end();
257
- readStream.destroy = function() {
258
- readStream.destroyed = true;
259
- };
260
- return readStream;
261
- };
262
-
263
- BufferSlicer.prototype.createWriteStream = function(options) {
264
- var bufferSlicer = this;
265
- options = options || {};
266
- var writeStream = new Writable(options);
267
- writeStream.start = options.start || 0;
268
- writeStream.endOffset = (options.end == null) ? this.buffer.length : +options.end;
269
- writeStream.bytesWritten = 0;
270
- writeStream.pos = writeStream.start;
271
- writeStream.destroyed = false;
272
- writeStream._write = function(buffer, encoding, callback) {
273
- if (writeStream.destroyed) return;
274
-
275
- var end = writeStream.pos + buffer.length;
276
- if (end > writeStream.endOffset) {
277
- var err = new Error("maximum file length exceeded");
278
- err.code = 'ETOOBIG';
279
- writeStream.destroyed = true;
280
- callback(err);
281
- return;
282
- }
283
- buffer.copy(bufferSlicer.buffer, writeStream.pos, 0, buffer.length);
284
-
285
- writeStream.bytesWritten += buffer.length;
286
- writeStream.pos = end;
287
- writeStream.emit('progress');
288
- callback();
289
- };
290
- writeStream.destroy = function() {
291
- writeStream.destroyed = true;
292
- };
293
- return writeStream;
294
- };
295
-
296
- BufferSlicer.prototype.ref = function() {
297
- this.refCount += 1;
298
- };
299
-
300
- BufferSlicer.prototype.unref = function() {
301
- this.refCount -= 1;
302
-
303
- if (this.refCount < 0) {
304
- throw new Error("invalid unref");
305
- }
306
- };
307
-
308
- function createFromBuffer(buffer, options) {
309
- return new BufferSlicer(buffer, options);
310
- }
311
-
312
- function createFromFd(fd, options) {
313
- return new FdSlicer(fd, options);
314
- }