filer/dist/filer.min.js

6 lines
151 KiB
JavaScript
Raw Normal View History

2014-08-20 19:57:09 +00:00
/*! filer 0.0.25 2014-08-20 */
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.Filer=t()}}(function(){var t;return function e(t,n,r){function i(a,s){if(!n[a]){if(!t[a]){var u="function"==typeof require&&require;if(!s&&u)return u(a,!0);if(o)return o(a,!0);throw Error("Cannot find module '"+a+"'")}var f=n[a]={exports:{}};t[a][0].call(f.exports,function(e){var n=t[a][1][e];return i(n?n:e)},f,f.exports,e,t,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;r.length>a;a++)i(r[a]);return i}({1:[function(e,n){(function(e){(function(){function r(t){var e=!1;return function(){if(e)throw Error("Callback was already called.");e=!0,t.apply(i,arguments)}}var i,o,a={};i=this,null!=i&&(o=i.async),a.noConflict=function(){return i.async=o,a};var s=function(t,e){if(t.forEach)return t.forEach(e);for(var n=0;t.length>n;n+=1)e(t[n],n,t)},u=function(t,e){if(t.map)return t.map(e);var n=[];return s(t,function(t,r,i){n.push(e(t,r,i))}),n},f=function(t,e,n){return t.reduce?t.reduce(e,n):(s(t,function(t,r,i){n=e(n,t,r,i)}),n)},c=function(t){if(Object.keys)return Object.keys(t);var e=[];for(var n in t)t.hasOwnProperty(n)&&e.push(n);return e};void 0!==e&&e.nextTick?(a.nextTick=e.nextTick,a.setImmediate="undefined"!=typeof setImmediate?function(t){setImmediate(t)}:a.nextTick):"function"==typeof setImmediate?(a.nextTick=function(t){setImmediate(t)},a.setImmediate=a.nextTick):(a.nextTick=function(t){setTimeout(t,0)},a.setImmediate=a.nextTick),a.each=function(t,e,n){if(n=n||function(){},!t.length)return n();var i=0;s(t,function(o){e(o,r(function(e){e?(n(e),n=function(){}):(i+=1,i>=t.length&&n(null))}))})},a.forEach=a.each,a.eachSeries=function(t,e,n){if(n=n||function(){},!t.length)return n();var r=0,i=function(){e(t[r],function(e){e?(n(e),n=function(){}):(r+=1,r>=t.length?n(null):i())})};i()},a.forEachSeries=a.eachSeries,a.eachLimit=function(t,e,n,r){var i=l(e);i.apply(null,[t,n,r])},a.forEachLimit=a.eachLimit;var l=function(t){return function(e,n,r){if(r=r||function(){},!e.length||0>=t)return r();var i=0,o=0,a=0;(function s(){if(i>=e.length)return r();for(;t>a&&e.length>o;)o+=1,a+=1,n(e[o-1],function(t){t?(r(t),r=function(){}):(i+=1,a-=1,i>=e.length?r():s())})})()}},d=function(t){return function(){var e=Array.prototype.slice.call(arguments);return t.apply(null,[a.each].concat(e))}},h=function(t,e){return function(){var n=Array.prototype.slice.call(arguments);return e.apply(null,[l(t)].concat(n))}},p=function(t){return function(){var e=Array.prototype.slice.call(arguments);return t.apply(null,[a.eachSeries].concat(e))}},g=function(t,e,n,r){var i=[];e=u(e,function(t,e){return{index:e,value:t}}),t(e,function(t,e){n(t.value,function(n,r){i[t.index]=r,e(n)})},function(t){r(t,i)})};a.map=d(g),a.mapSeries=p(g),a.mapLimit=function(t,e,n,r){return m(e)(t,n,r)};var m=function(t){return h(t,g)};a.reduce=function(t,e,n,r){a.eachSeries(t,function(t,r){n(e,t,function(t,n){e=n,r(t)})},function(t){r(t,e)})},a.inject=a.reduce,a.foldl=a.reduce,a.reduceRight=function(t,e,n,r){var i=u(t,function(t){return t}).reverse();a.reduce(i,e,n,r)},a.foldr=a.reduceRight;var v=function(t,e,n,r){var i=[];e=u(e,function(t,e){return{index:e,value:t}}),t(e,function(t,e){n(t.value,function(n){n&&i.push(t),e()})},function(){r(u(i.sort(function(t,e){return t.index-e.index}),function(t){return t.value}))})};a.filter=d(v),a.filterSeries=p(v),a.select=a.filter,a.selectSeries=a.filterSeries;var b=function(t,e,n,r){var i=[];e=u(e,function(t,e){return{index:e,value:t}}),t(e,function(t,e){n(t.value,function(n){n||i.push(t),e()})},function(){r(u(i.sort(function(t,e){return t.index-e.index}),function(t){return t.value}))})};a.reject=d(b),a.rejectSeries=p(b);var y=function(t,e,n,r){t(e,function(t,e){n(t,function(n){n?(r(t),r=function(){}):e()})},function(){r()})};a.detect=d(y),a.detectSeries=p(y),a.some=function(t,e,n){a.each(t,function(t,r){e(t,function(t){t&&(n(!0),n=function(){}),r()})},f
n?(n=Number(n),n>l&&(n=l)):n=l,r=((r||"utf8")+"").toLowerCase();var d;switch(r){case"hex":d=i(this,t,e,n);break;case"utf8":case"utf-8":d=o(this,t,e,n);break;case"ascii":d=a(this,t,e,n);break;case"binary":d=s(this,t,e,n);break;case"base64":d=u(this,t,e,n);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":d=f(this,t,e,n);break;default:throw Error("Unknown encoding")}return d},r.prototype.toString=function(t,e,n){var r=this;if(t=((t||"utf8")+"").toLowerCase(),e=Number(e)||0,n=void 0===n?r.length:Number(n),n===e)return"";var i;switch(t){case"hex":i=p(r,e,n);break;case"utf8":case"utf-8":i=l(r,e,n);break;case"ascii":i=d(r,e,n);break;case"binary":i=h(r,e,n);break;case"base64":i=c(r,e,n);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":i=g(r,e,n);break;default:throw Error("Unknown encoding")}return i},r.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},r.prototype.equals=function(t){return Y(r.isBuffer(t),"Argument must be a Buffer"),0===r.compare(this,t)},r.prototype.compare=function(t){return Y(r.isBuffer(t),"Argument must be a Buffer"),r.compare(this,t)},r.prototype.copy=function(t,e,n,i){var o=this;if(n||(n=0),i||0===i||(i=this.length),e||(e=0),i!==n&&0!==t.length&&0!==o.length){Y(i>=n,"sourceEnd < sourceStart"),Y(e>=0&&t.length>e,"targetStart out of bounds"),Y(n>=0&&o.length>n,"sourceStart out of bounds"),Y(i>=0&&o.length>=i,"sourceEnd out of bounds"),i>this.length&&(i=this.length),i-n>t.length-e&&(i=t.length-e+n);var a=i-n;if(100>a||!r._useTypedArrays)for(var s=0;a>s;s++)t[s+e]=this[s+n];else t._set(this.subarray(n,n+a),e)}},r.prototype.slice=function(t,e){var n=this.length;if(t=C(t,n,0),e=C(e,n,n),r._useTypedArrays)return r._augment(this.subarray(t,e));for(var i=e-t,o=new r(i,void 0,!0),a=0;i>a;a++)o[a]=this[a+t];return o},r.prototype.get=function(t){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(t)},r.prototype.set=function(t,e){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(t,e)},r.prototype.readUInt8=function(t,e){return e||(Y(void 0!==t&&null!==t,"missing offset"),Y(this.length>t,"Trying to read beyond buffer length")),t>=this.length?void 0:this[t]},r.prototype.readUInt16LE=function(t,e){return m(this,t,!0,e)},r.prototype.readUInt16BE=function(t,e){return m(this,t,!1,e)},r.prototype.readUInt32LE=function(t,e){return v(this,t,!0,e)},r.prototype.readUInt32BE=function(t,e){return v(this,t,!1,e)},r.prototype.readInt8=function(t,e){if(e||(Y(void 0!==t&&null!==t,"missing offset"),Y(this.length>t,"Trying to read beyond buffer length")),!(t>=this.length)){var n=128&this[t];return n?-1*(255-this[t]+1):this[t]}},r.prototype.readInt16LE=function(t,e){return b(this,t,!0,e)},r.prototype.readInt16BE=function(t,e){return b(this,t,!1,e)},r.prototype.readInt32LE=function(t,e){return y(this,t,!0,e)},r.prototype.readInt32BE=function(t,e){return y(this,t,!1,e)},r.prototype.readFloatLE=function(t,e){return _(this,t,!0,e)},r.prototype.readFloatBE=function(t,e){return _(this,t,!1,e)},r.prototype.readDoubleLE=function(t,e){return w(this,t,!0,e)},r.prototype.readDoubleBE=function(t,e){return w(this,t,!1,e)},r.prototype.writeUInt8=function(t,e,n){return n||(Y(void 0!==t&&null!==t,"missing value"),Y(void 0!==e&&null!==e,"missing offset"),Y(this.length>e,"trying to write beyond buffer length"),P(t,255)),e>=this.length?void 0:(this[e]=t,e+1)},r.prototype.writeUInt16LE=function(t,e,n){return E(this,t,e,!0,n)},r.prototype.writeUInt16BE=function(t,e,n){return E(this,t,e,!1,n)},r.prototype.writeUInt32LE=function(t,e,n){return x(this,t,e,!0,n)},r.prototype.writeUInt32BE=function(t,e,n){return x(this,t,e,!1,n)},r.prototype.writeInt8=function(t,e,n){return n||(Y(void 0!==t&&null!==t,"missing value"),Y(void 0!==e&&null!==e,"missing offset"),Y(this.length>e,"Trying to write beyond buffer length"),V(t,127,-128)),e>=this.length?void 0:(t>=0?this.writeUInt8(t,e,n):this.writeUInt8(255+t+1,e,n),e+1)},r.prototype.writeInt16LE=function(t,e,n){return I(this,t,e,!0,n)},r.prototype.writeInt16BE=functi
this.reader.setIndex(t),this.checkSignature(s.ZIP64_CENTRAL_DIRECTORY_LOCATOR),this.readBlockZip64EndOfCentralLocator(),this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir),this.checkSignature(s.ZIP64_CENTRAL_DIRECTORY_END),this.readBlockZip64EndOfCentral()}},prepareReader:function(t){var e=a.getTypeOf(t);this.reader="string"!==e||f.uint8array?"nodebuffer"===e?new i(t):new o(a.transformTo("uint8array",t)):new r(t,this.loadOptions.optimizedBinaryString)},load:function(t){this.prepareReader(t),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},e.exports=n},{"./nodeBufferReader":20,"./signature":22,"./stringReader":23,"./support":24,"./uint8ArrayReader":25,"./utils":26,"./zipEntry":28}],28:[function(t,e){"use strict";function n(t,e){this.options=t,this.loadOptions=e}var r=t("./stringReader"),i=t("./utils"),o=t("./compressedObject"),a=t("./object");n.prototype={isEncrypted:function(){return 1===(1&this.bitFlag)},useUTF8:function(){return 2048===(2048&this.bitFlag)},prepareCompressedContent:function(t,e,n){return function(){var r=t.index;t.setIndex(e);var i=t.readData(n);return t.setIndex(r),i}},prepareContent:function(t,e,n,r,o){return function(){var t=i.transformTo(r.uncompressInputType,this.getCompressedContent()),e=r.uncompress(t);if(e.length!==o)throw Error("Bug : uncompressed data size mismatch");return e}},readLocalPart:function(t){var e,n;if(t.skip(22),this.fileNameLength=t.readInt(2),n=t.readInt(2),this.fileName=t.readString(this.fileNameLength),t.skip(n),-1==this.compressedSize||-1==this.uncompressedSize)throw Error("Bug or corrupted zip : didn't get enough informations from the central directory (compressedSize == -1 || uncompressedSize == -1)");if(e=i.findCompression(this.compressionMethod),null===e)throw Error("Corrupted zip : compression "+i.pretty(this.compressionMethod)+" unknown (inner file : "+this.fileName+")");if(this.decompressed=new o,this.decompressed.compressedSize=this.compressedSize,this.decompressed.uncompressedSize=this.uncompressedSize,this.decompressed.crc32=this.crc32,this.decompressed.compressionMethod=this.compressionMethod,this.decompressed.getCompressedContent=this.prepareCompressedContent(t,t.index,this.compressedSize,e),this.decompressed.getContent=this.prepareContent(t,t.index,this.compressedSize,e,this.uncompressedSize),this.loadOptions.checkCRC32&&(this.decompressed=i.transformTo("string",this.decompressed.getContent()),a.crc32(this.decompressed)!==this.crc32))throw Error("Corrupted zip : CRC32 mismatch")},readCentralPart:function(t){if(this.versionMadeBy=t.readString(2),this.versionNeeded=t.readInt(2),this.bitFlag=t.readInt(2),this.compressionMethod=t.readString(2),this.date=t.readDate(),this.crc32=t.readInt(4),this.compressedSize=t.readInt(4),this.uncompressedSize=t.readInt(4),this.fileNameLength=t.readInt(2),this.extraFieldsLength=t.readInt(2),this.fileCommentLength=t.readInt(2),this.diskNumberStart=t.readInt(2),this.internalFileAttributes=t.readInt(2),this.externalFileAttributes=t.readInt(4),this.localHeaderOffset=t.readInt(4),this.isEncrypted())throw Error("Encrypted zip are not supported");this.fileName=t.readString(this.fileNameLength),this.readExtraFields(t),this.parseZIP64ExtraField(t),this.fileComment=t.readString(this.fileCommentLength),this.dir=16&this.externalFileAttributes?!0:!1},parseZIP64ExtraField:function(){if(this.extraFields[1]){var t=new r(this.extraFields[1].value);this.uncompressedSize===i.MAX_VALUE_32BITS&&(this.uncompressedSize=t.readInt(8)),this.compressedSize===i.MAX_VALUE_32BITS&&(this.compressedSize=t.readInt(8)),this.localHeaderOffset===i.MAX_VALUE_32BITS&&(this.localHeaderOffset=t.readInt(8)),this.diskNumberStart===i.MAX_VALUE_32BITS&&(this.diskNumberStart=t.readInt(4))}},readExtraFields:function(t){var e,n,r,i=t.index;for(this.extraFields=this.extraFields||{};t.index<i+this.extraFieldsLength;)e=t.readInt(2),n=t.readInt(2),r=t.readString(n),this.extraFields[e]={id:e,length:n,value:r}},handleUTF8:function(){if(this.useUTF8())this.fileName=a.utf8decode(this.fileName),this.fileComment=a.utf8decode(this.fileComment);else{var t=this
case U:if(1024&n.flags){for(;16>h;){if(0===u)break t;u--,d+=i[a++]<<h,h+=8}n.length=d,n.head&&(n.head.extra_len=d),512&n.flags&&(Oe[0]=255&d,Oe[1]=255&d>>>8,n.check=y(n.check,Oe,2,0)),d=0,h=0}else n.head&&(n.head.extra=null);n.mode=P;case P:if(1024&n.flags&&(m=n.length,m>u&&(m=u),m&&(n.head&&(Ee=n.head.extra_len-n.length,n.head.extra||(n.head.extra=Array(n.head.extra_len)),v.arraySet(n.head.extra,i,a,m,Ee)),512&n.flags&&(n.check=y(n.check,i,m,a)),u-=m,a+=m,n.length-=m),n.length))break t;n.length=0,n.mode=V;case V:if(2048&n.flags){if(0===u)break t;m=0;do Ee=i[a+m++],n.head&&Ee&&65536>n.length&&(n.head.name+=String.fromCharCode(Ee));while(Ee&&u>m);if(512&n.flags&&(n.check=y(n.check,i,m,a)),u-=m,a+=m,Ee)break t}else n.head&&(n.head.name=null);n.length=0,n.mode=Z;case Z:if(4096&n.flags){if(0===u)break t;m=0;do Ee=i[a+m++],n.head&&Ee&&65536>n.length&&(n.head.comment+=String.fromCharCode(Ee));while(Ee&&u>m);if(512&n.flags&&(n.check=y(n.check,i,m,a)),u-=m,a+=m,Ee)break t}else n.head&&(n.head.comment=null);n.mode=Y;case Y:if(512&n.flags){for(;16>h;){if(0===u)break t;u--,d+=i[a++]<<h,h+=8}if(d!==(65535&n.check)){t.msg="header crc mismatch",n.mode=le;break}d=0,h=0}n.head&&(n.head.hcrc=1&n.flags>>9,n.head.done=!0),t.adler=n.check=0,n.mode=W;break;case X:for(;32>h;){if(0===u)break t;u--,d+=i[a++]<<h,h+=8}t.adler=n.check=r(d),d=0,h=0,n.mode=H;case H:if(0===n.havedict)return t.next_out=s,t.avail_out=f,t.next_in=a,t.avail_in=u,n.hold=d,n.bits=h,C;t.adler=n.check=1,n.mode=W;case W:if(e===A||e===O)break t;case q:if(n.last){d>>>=7&h,h-=7&h,n.mode=ue;break}for(;3>h;){if(0===u)break t;u--,d+=i[a++]<<h,h+=8}switch(n.last=1&d,d>>>=1,h-=1,3&d){case 0:n.mode=J;break;case 1:if(c(n),n.mode=ee,e===O){d>>>=2,h-=2;break t}break;case 2:n.mode=Q;break;case 3:t.msg="invalid block type",n.mode=le}d>>>=2,h-=2;break;case J:for(d>>>=7&h,h-=7&h;32>h;){if(0===u)break t;u--,d+=i[a++]<<h,h+=8}if((65535&d)!==(65535^d>>>16)){t.msg="invalid stored block lengths",n.mode=le;break}if(n.length=65535&d,d=0,h=0,n.mode=K,e===O)break t;case K:n.mode=G;case G:if(m=n.length){if(m>u&&(m=u),m>f&&(m=f),0===m)break t;v.arraySet(o,i,a,m,s),u-=m,a+=m,f-=m,s+=m,n.length-=m;break}n.mode=W;break;case Q:for(;14>h;){if(0===u)break t;u--,d+=i[a++]<<h,h+=8}if(n.nlen=(31&d)+257,d>>>=5,h-=5,n.ndist=(31&d)+1,d>>>=5,h-=5,n.ncode=(15&d)+4,d>>>=4,h-=4,n.nlen>286||n.ndist>30){t.msg="too many length or distance symbols",n.mode=le;break}n.have=0,n.mode=$;case $:for(;n.have<n.ncode;){for(;3>h;){if(0===u)break t;u--,d+=i[a++]<<h,h+=8}n.lens[Se[n.have++]]=7&d,d>>>=3,h-=3}for(;19>n.have;)n.lens[Se[n.have++]]=0;if(n.lencode=n.lendyn,n.lenbits=7,Ie={bits:n.lenbits},xe=w(E,n.lens,0,19,n.lencode,0,n.work,Ie),n.lenbits=Ie.bits,xe){t.msg="invalid code lengths set",n.mode=le;break}n.have=0,n.mode=te;case te:for(;n.have<n.nlen+n.ndist;){for(;Ae=n.lencode[d&(1<<n.lenbits)-1],me=Ae>>>24,ve=255&Ae>>>16,be=65535&Ae,!(h>=me);){if(0===u)break t;u--,d+=i[a++]<<h,h+=8}if(16>be)d>>>=me,h-=me,n.lens[n.have++]=be;else{if(16===be){for(ke=me+2;ke>h;){if(0===u)break t;u--,d+=i[a++]<<h,h+=8}if(d>>>=me,h-=me,0===n.have){t.msg="invalid bit length repeat",n.mode=le;break}Ee=n.lens[n.have-1],m=3+(3&d),d>>>=2,h-=2}else if(17===be){for(ke=me+3;ke>h;){if(0===u)break t;u--,d+=i[a++]<<h,h+=8}d>>>=me,h-=me,Ee=0,m=3+(7&d),d>>>=3,h-=3}else{for(ke=me+7;ke>h;){if(0===u)break t;u--,d+=i[a++]<<h,h+=8}d>>>=me,h-=me,Ee=0,m=11+(127&d),d>>>=7,h-=7}if(n.have+m>n.nlen+n.ndist){t.msg="invalid bit length repeat",n.mode=le;break}for(;m--;)n.lens[n.have++]=Ee}}if(n.mode===le)break;if(0===n.lens[256]){t.msg="invalid code -- missing end-of-block",n.mode=le;break}if(n.lenbits=9,Ie={bits:n.lenbits},xe=w(x,n.lens,0,n.nlen,n.lencode,0,n.work,Ie),n.lenbits=Ie.bits,xe){t.msg="invalid literal/lengths set",n.mode=le;break}if(n.distbits=6,n.distcode=n.distdyn,Ie={bits:n.distbits},xe=w(I,n.lens,n.nlen,n.ndist,n.distcode,0,n.work,Ie),n.distbits=Ie.bits,xe){t.msg="invalid distances set",n.mode=le;break}if(n.mode=ee,e===O)break t;case ee:n.mode=ne;case ne:if(u>=6&&f>=258){t.next_out=s,t.avail_out=f,t.next_in=a,t.avail_in=u,n.hold=d,n.bits=h,_(t,g),s=t.next_out
}function z(t,e,n,r,o){D(n,o)&&i(e,n,r,o)}function F(t,e,r,i,o){o=arguments[arguments.length-1],D(r,o)&&u(e,r,n(o))}function M(t,e,r,i){D(r,i)&&f(e,r,n(i))}function U(t,e,n,r){function i(e,n){if(e)r(e);else{var i=new Ze(n,t.name);r(null,i)}}D(n,r)&&p(e,n,i)}function P(t,e,n,r){function i(e,n){if(e)r(e);else{var i=new Ze(n,t.name);r(null,i)}}var o=t.openFiles[n];o?g(e,o,i):r(new Fe.EBADF)}function V(t,e,r,i,o){D(r,o)&&D(i,o)&&v(e,r,i,n(o))}function Z(t,e,r,i){D(r,i)&&b(e,r,n(i))}function Y(t,e,r,i,o,a,s,u){function f(t,e){u(t,e||0,i)}o=void 0===o?0:o,a=void 0===a?i.length-o:a,u=arguments[arguments.length-1];var c=t.openFiles[r];c?de(c.flags).contains(Oe)?h(e,c,i,o,a,s,n(f)):u(new Fe.EBADF("descriptor does not permit reading")):u(new Fe.EBADF)}function X(t,e,n,r,i){if(i=arguments[arguments.length-1],r=N(r,null,"r"),D(n,i)){var o=j(r.flag||"r");return o?(c(e,n,o,function(a,s){function u(){t.releaseDescriptor(c)}if(a)return i(a);var f=new Ue(n,s.id,o,0),c=t.allocDescriptor(f);g(e,f,function(o,a){if(o)return u(),i(o);var s=new Ze(a,t.name);if(s.isDirectory())return u(),i(new Fe.EISDIR("illegal operation on directory",n));var c=s.size,l=new Ye(c);l.fill(0),h(e,f,l,0,c,0,function(t){if(u(),t)return i(t);var e;e="utf8"===r.encoding?ze.decode(l):l,i(null,e)})})}),void 0):i(new Fe.EINVAL("flags is not valid",n))}}function H(t,e,r,i,o,a,s,u){u=arguments[arguments.length-1],o=void 0===o?0:o,a=void 0===a?i.length-o:a;var f=t.openFiles[r];f?de(f.flags).contains(Se)?a>i.length-o?u(new Fe.EIO("intput buffer is too small")):d(e,f,i,o,a,s,n(u)):u(new Fe.EBADF("descriptor does not permit writing")):u(new Fe.EBADF)}function W(t,e,n,r,i,o){if(o=arguments[arguments.length-1],i=N(i,"utf8","w"),D(n,o)){var a=j(i.flag||"w");if(!a)return o(new Fe.EINVAL("flags is not valid",n));r=r||"","number"==typeof r&&(r=""+r),"string"==typeof r&&"utf8"===i.encoding&&(r=ze.encode(r)),c(e,n,a,function(i,s){if(i)return o(i);var u=new Ue(n,s.id,a,0),f=t.allocDescriptor(u);l(e,u,r,0,r.length,function(e){return t.releaseDescriptor(f),e?o(e):(o(null),void 0)})})}}function q(t,e,n,r,i,o){if(o=arguments[arguments.length-1],i=N(i,"utf8","a"),D(n,o)){var a=j(i.flag||"a");if(!a)return o(new Fe.EINVAL("flags is not valid",n));r=r||"","number"==typeof r&&(r=""+r),"string"==typeof r&&"utf8"===i.encoding&&(r=ze.encode(r)),c(e,n,a,function(i,s){if(i)return o(i);var u=new Ue(n,s.id,a,s.size),f=t.allocDescriptor(u);d(e,u,r,0,r.length,u.position,function(e){return t.releaseDescriptor(f),e?o(e):(o(null),void 0)})})}}function J(t,e,n,r){function i(t){r(t?!1:!0)}U(t,e,n,i)}function K(t,e,r,i,o){D(r,o)&&S(e,r,i,n(o))}function G(t,e,r,i,o){var a=t.openFiles[r];a?T(e,a,i,n(o)):o(new Fe.EBADF)}function Q(t,e,r,i,o,a,s){"function"==typeof a&&(s=a,a=null),D(r,s)&&A(e,r,i,o,a,n(s))}function $(t,e,r,i,o,a,s){"function"==typeof a&&(s=a,a=null);var u=t.openFiles[r];u?de(u.flags).contains(Se)?O(e,u,i,o,a,n(s)):s(new Fe.EBADF("descriptor does not permit writing")):s(new Fe.EBADF)}function te(t,e,r,i,o){D(r,o)&&C(e,r,i,n(o))}function ee(t,e,r,i,o){var a=t.openFiles[r];a?de(a.flags).contains(Se)?R(e,a,i,n(o)):o(new Fe.EBADF("descriptor does not permit writing")):o(new Fe.EBADF)}function ne(t,e,n,r,i,o){function a(t,e){t?o(t):0>e.size+r?o(new Fe.EINVAL("resulting file offset would be negative")):(s.position=e.size+r,o(null,s.position))}var s=t.openFiles[n];s||o(new Fe.EBADF),"SET"===i?0>r?o(new Fe.EINVAL("resulting file offset would be negative")):(s.position=r,o(null,s.position)):"CUR"===i?0>s.position+r?o(new Fe.EINVAL("resulting file offset would be negative")):(s.position+=r,o(null,s.position)):"END"===i?g(e,s,a):o(new Fe.EINVAL("whence argument is not a proper value"))}function re(t,e,r,i){D(r,i)&&y(e,r,n(i))}function ie(t,e,r,i,o,a){if(D(r,a)){var s=Date.now();i=i?i:s,o=o?o:s,I(e,r,i,o,n(a))}}function oe(t,e,r,i,o,a){var s=Date.now();i=i?i:s,o=o?o:s;var u=t.openFiles[r];u?de(u.flags).contains(Se)?k(e,u,i,o,n(a)):a(new Fe.EBADF("descriptor does not permit writing")):a(new Fe.EBADF)}function ae(t,e,r,i,o){function a(t){t?o(t):b(e,r,n(o))}D(r,o)&&D(i,o)&&v(e,r,i,a)}function se(t,e,r,i,o,a){a