UNPKG

browserfs

Version:

A filesystem in your browser!

2 lines 249 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.BrowserFS=e():t.BrowserFS=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){(function(t,r,i,o){"use strict";function s(t){if(t)return t;throw new Fe(be.EIO,"Initialize BrowserFS with a file system using BrowserFS.initialize(filesystem)")}function a(t,e){switch(typeof t){case"number":return t;case"string":var n=parseInt(t,8);return isNaN(n)?e:n;default:return e}}function c(t){if(t instanceof Date)return t;if("number"==typeof t)return new Date(1e3*t);throw new Fe(be.EINVAL,"Invalid time.")}function u(t){if(t.indexOf("\0")>=0)throw new Fe(be.EINVAL,"Path must be a string without null bytes.");if(""===t)throw new Fe(be.EINVAL,"Path must not be empty.");return ke.resolve(t)}function f(t,e,n,r){switch(typeof t){case"object":return{encoding:"undefined"!=typeof t.encoding?t.encoding:e,flag:"undefined"!=typeof t.flag?t.flag:n,mode:a(t.mode,r)};case"string":return{encoding:t,flag:n,mode:r};default:return{encoding:e,flag:n,mode:r}}}function h(){}function p(t,e,n,r,i){return t<e||n<e?t>n?n+1:t+1:r===i?e:e+1}function l(t,e){if(t===e)return 0;if(t.length>e.length){var n=t;t=e,e=n}for(var r=t.length,i=e.length;r>0&&t.charCodeAt(r-1)===e.charCodeAt(i-1);)r--,i--;for(var o=0;o<r&&t.charCodeAt(o)===e.charCodeAt(o);)o++;if(r-=o,i-=o,0===r||1===i)return i;for(var s=new Array(r<<1),a=0;a<r;)s[r+a]=t.charCodeAt(o+a),s[a]=++a;var c,u,f,h,l;for(c=0;c+3<i;)for(var d=e.charCodeAt(o+(u=c)),y=e.charCodeAt(o+(f=c+1)),g=e.charCodeAt(o+(h=c+2)),v=e.charCodeAt(o+(l=c+3)),m=c+=4,_=0;_<r;){var w=s[r+_],E=s[_];u=p(E,u,f,d,w),f=p(u,f,h,y,w),h=p(f,h,l,g,w),m=p(h,l,m,v,w),s[_++]=m,l=h,h=f,f=u,u=E}for(var b=0;c<i;){var S=e.charCodeAt(o+(u=c));b=++c;for(var k=0;k<r;k++){var I=s[k];s[k]=b=I<u||b<u?I>b?b+1:I+1:S===s[r+k]?u:u+1,u=I}}return b}function d(t,e,n){t&&console.warn("["+e+"] Direct file system constructor usage is deprecated for this file system, and will be removed in the next major version. Please use the '"+e+".Create("+JSON.stringify(n)+", callback)' method instead. See https://github.com/jvilk/BrowserFS/issues/176 for more details.")}function y(){throw new Error("BFS has reached an impossible code path; please file a bug.")}function g(t,e,n){n.existsSync(t)||(g(ke.dirname(t),e,n),n.mkdirSync(t,e))}function v(t){var e=m(t),n=e.byteOffset,r=e.byteLength;return 0===n&&r===e.buffer.byteLength?e.buffer:e.buffer.slice(n,n+r)}function m(t){return t instanceof Uint8Array?t:new Uint8Array(t)}function _(e){return e instanceof t?e:e instanceof Uint8Array?w(e):t.from(e)}function w(e){return e instanceof t?e:0===e.byteOffset&&e.byteLength===e.buffer.byteLength?E(e.buffer):t.from(e.buffer,e.byteOffset,e.byteLength)}function E(e){return t.from(e)}function b(t,e,n){if(void 0===e&&(e=0),void 0===n&&(n=t.length),e<0||n<0||n>t.length||e>n)throw new TypeError("Invalid slice bounds on buffer of length "+t.length+": ["+e+", "+n+"]");if(0===t.length)return S();var r=m(t),i=t[0],o=(i+1)%255;return t[0]=o,r[0]===o?(r[0]=i,w(r.slice(e,n))):(t[0]=i,w(r.subarray(e,n)))}function S(){return je?je:je=t.alloc(0)}function k(e,n){t.isBuffer(e)?n():n(new Fe(be.EINVAL,"option must be a Buffer."))}function I(t,e,n){function r(t){a||(t&&(a=!0,n(t)),s--,0===s&&c&&n())}var i=t.Options,o=t.Name,s=0,a=!1,c=!1,u=function(t){if(i.hasOwnProperty(t)){var c=i[t],u=e[t];if(void 0===u||null===u){if(!c.optional){var f=Object.keys(e).filter(function(t){return!(t in i)}).map(function(e){return{str:e,distance:l(t,e)}}).filter(function(t){return t.distance<5}).sort(function(t,e){return t.distance-e.distance});return a?{}:(a=!0,{v:n(new Fe(be.EINVAL,"["+o+"] Required option '"+t+"' not provided."+(f.length>0?" You provided unrecognized option '"+f[0].str+"'; perhaps you meant to type '"+t+"'.":"")+"\nOption description: "+c.description))})}}else{var h=!1;if(h=Array.isArray(c.type)?c.type.indexOf(typeof u)!==-1:typeof u===c.type,!h)return a?{}:(a=!0,{v:n(new Fe(be.EINVAL,"["+o+"] Value provided for option "+t+" is not the proper type. Expected "+(Array.isArray(c.type)?"one of {"+c.type.join(", ")+"}":c.type)+", but received "+typeof u+"\nOption description: "+c.description))});c.validator&&(s++,c.validator(u,r))}}};for(var f in i){var h=u(f);if(h)return h.v}c=!0,0!==s||a||n()}function O(t,e,n){switch(n.length){case 0:return t.call(e);case 1:return t.call(e,n[0]);case 2:return t.call(e,n[0],n[1]);case 3:return t.call(e,n[0],n[1],n[2])}return t.apply(e,n)}function F(t,e,n){return e=Ge(void 0===e?t.length-1:e,0),function(){for(var r=arguments,i=-1,o=Ge(r.length-e,0),s=Array(o);++i<o;)s[i]=r[e+i];i=-1;for(var a=Array(e+1);++i<e;)a[i]=r[i];return a[e]=n(s),O(t,this,a)}}function N(t){return t}function R(t,e){return F(t,e,N)}function L(t){return R(function(e,n){var r=Qe(function(n,r){var i=this;return t(e,function(t,e){t.apply(i,n.concat(e))},r)});return n.length?r.apply(this,n):r})}function T(t){var e=on.call(t,an),n=t[an];try{t[an]=void 0;var r=!0}catch(t){}var i=sn.call(t);return r&&(e?t[an]=n:delete t[an]),i}function x(t){return un.call(t)}function A(t){return null==t?void 0===t?hn:fn:pn&&pn in Object(t)?T(t):x(t)}function D(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function P(t){if(!D(t))return!1;var e=A(t);return e==dn||e==yn||e==ln||e==gn}function C(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=vn}function U(t){return null!=t&&C(t.length)&&!P(t)}function M(){}function j(t){return function(){if(null!==t){var e=t;t=null,e.apply(this,arguments)}}}function B(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r}function z(t){return null!=t&&"object"==typeof t}function q(t){return z(t)&&A(t)==En}function V(){return!1}function W(t,e){return e=null==e?An:e,!!e&&("number"==typeof t||Dn.test(t))&&t>-1&&t%1==0&&t<e}function H(t){return z(t)&&C(t.length)&&!!or[A(t)]}function Z(t){return function(e){return t(e)}}function Y(t,e){var n=On(t),r=!n&&In(t),i=!n&&!r&&xn(t),o=!n&&!r&&!i&&pr(t),s=n||r||i||o,a=s?B(t.length,String):[],c=a.length;for(var u in t)!e&&!dr.call(t,u)||s&&("length"==u||i&&("offset"==u||"parent"==u)||o&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||W(u,c))||a.push(u);return a}function X(t){var e=t&&t.constructor,n="function"==typeof e&&e.prototype||yr;return t===n}function K(t,e){return function(n){return t(e(n))}}function J(t){if(!X(t))return gr(t);var e=[];for(var n in Object(t))mr.call(t,n)&&"constructor"!=n&&e.push(n);return e}function G(t){return U(t)?Y(t):J(t)}function Q(t){var e=-1,n=t.length;return function(){return++e<n?{value:t[e],key:e}:null}}function $(t){var e=-1;return function(){var n=t.next();return n.done?null:(e++,{value:n.value,key:e})}}function tt(t){var e=G(t),n=-1,r=e.length;return function(){var i=e[++n];return n<r?{value:t[i],key:i}:null}}function et(t){if(U(t))return Q(t);var e=wn(t);return e?$(e):tt(t)}function nt(t){return function(){if(null===t)throw new Error("Callback was already called.");var e=t;t=null,e.apply(this,arguments)}}function rt(t){return function(e,n,r){function i(t,e){if(c-=1,t)a=!0,r(t);else{if(e===mn||a&&c<=0)return a=!0,r(null);o()}}function o(){for(;c<t&&!a;){var e=s();if(null===e)return a=!0,void(c<=0&&r(null));c+=1,n(e.value,e.key,nt(i))}}if(r=j(r||M),t<=0||!e)return r(null);var s=et(e),a=!1,c=0;o()}}function it(t,e,n,r){rt(e)(t,n,r)}function ot(t,e){return function(n,r,i){return t(n,e,r,i)}}function st(t,e,n){function r(t,e){t?n(t):++o!==s&&e!==mn||n(null)}n=j(n||M);var i=0,o=0,s=t.length;for(0===s&&n(null);i<s;i++)e(t[i],i,nt(r))}function at(t){return function(e,n,r){return t(wr,e,n,r)}}function ct(t,e,n,r){r=r||M,e=e||[];var i=[],o=0;t(e,function(t,e,r){var s=o++;n(t,function(t,e){i[s]=e,r(t)})},function(t){r(t,i)})}function ut(t){return function(e,n,r,i){return t(rt(n),e,r,i)}}function ft(t,e){for(var n=-1,r=null==t?0:t.length;++n<r&&e(t[n],n,t)!==!1;);return t}function ht(t){return function(e,n,r){for(var i=-1,o=Object(e),s=r(e),a=s.length;a--;){var c=s[t?a:++i];if(n(o[c],c,o)===!1)break}return e}}function pt(t){setTimeout(t,0)}function lt(t){return R(function(e,n){t(function(){e.apply(null,n)})})}function dt(t,e,n,r){r=j(r||M),Vr(t,function(t,r,i){n(e,t,function(t,n){e=n,i(t)})},function(t){r(t,e)})}function yt(t){return R(function(e,n){e.apply(null,n.concat(R(function(e,n){"object"==typeof console&&(e?console.error&&console.error(e):console[t]&&ft(n,function(e){console[t](e)}))})))})}function gt(t){return function(e,n,r){return t(e,r)}}function vt(t,e,n){wr(t,gt(e),n)}function mt(){Zr||(Zr={},Zr[Dropbox.ApiError.NETWORK_ERROR]=be.EIO,Zr[Dropbox.ApiError.INVALID_PARAM]=be.EINVAL,Zr[Dropbox.ApiError.INVALID_TOKEN]=be.EPERM,Zr[Dropbox.ApiError.OAUTH_ERROR]=be.EPERM,Zr[Dropbox.ApiError.NOT_FOUND]=be.ENOENT,Zr[Dropbox.ApiError.INVALID_METHOD]=be.EINVAL,Zr[Dropbox.ApiError.NOT_ACCEPTABLE]=be.EINVAL,Zr[Dropbox.ApiError.CONFLICT]=be.EINVAL,Zr[Dropbox.ApiError.RATE_LIMITED]=be.EBUSY,Zr[Dropbox.ApiError.SERVER_ERROR]=be.EBUSY,Zr[Dropbox.ApiError.OVER_QUOTA]=be.ENOSPC)}function _t(t){return t&&t.stat.isFile}function wt(t){return t&&t.stat.isFolder}function Et(t){return null===t||void 0===t||"object"==typeof t&&"number"==typeof t.byteLength}function bt(t,e){void 0===e&&(e="");for(var n=t.errno,r=t.node,i=[];r&&(i.unshift(r.name),r!==r.parent);)r=r.parent;return new Fe(n,Ie[n],i.length>0?"/"+i.join("/"):e)}function St(t,e){if(null!==e&&"object"==typeof e){var n=e,r=n.path;r&&(r="/"+ke.relative(t,r),n.message=n.message.replace(n.path,r),n.path=r)}return e}function kt(t,e){return"function"==typeof e?function(n){arguments.length>0&&(arguments[0]=St(t,n)),e.apply(null,arguments)}:e}function It(t,e,n){return"Sync"!==t.slice(t.length-4)?function(){return arguments.length>0&&(e&&(arguments[0]=ke.join(this._folder,arguments[0])),n&&(arguments[1]=ke.join(this._folder,arguments[1])),arguments[arguments.length-1]=kt(this._folder,arguments[arguments.length-1])),this._wrapped[t].apply(this._wrapped,arguments)}:function(){try{return e&&(arguments[0]=ke.join(this._folder,arguments[0])),n&&(arguments[1]=ke.join(this._folder,arguments[1])),this._wrapped[t].apply(this._wrapped,arguments)}catch(t){throw St(this._folder,t)}}}function Ot(t){return t.isDirectory}function Ft(t,e,n,r){if("undefined"!=typeof navigator.webkitPersistentStorage)switch(t){case ti.PERSISTENT:navigator.webkitPersistentStorage.requestQuota(e,n,r);break;case ti.TEMPORARY:navigator.webkitTemporaryStorage.requestQuota(e,n,r);break;default:r(new TypeError("Invalid storage type: "+t))}else ti.webkitStorageInfo.requestQuota(t,e,n,r)}function Nt(t){return Array.prototype.slice.call(t||[],0)}function Rt(t,e,n){switch(t.name){case"PathExistsError":return Fe.EEXIST(e);case"QuotaExceededError":return Fe.FileError(be.ENOSPC,e);case"NotFoundError":return Fe.ENOENT(e);case"SecurityError":return Fe.FileError(be.EACCES,e);case"InvalidModificationError":return Fe.FileError(be.EPERM,e);case"TypeMismatchError":return Fe.FileError(n?be.ENOTDIR:be.EISDIR,e);case"EncodingError":case"InvalidStateError":case"NoModificationAllowedError":default:return Fe.FileError(be.EINVAL,e)}}function Lt(){return si?si:si=t.from("{}")}function Tt(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0,n="x"===t?e:3&e|8;return n.toString(16)})}function xt(t,e){return!t||(e(t),!1)}function At(t,e,n){return!t||(e.abort(function(){n(t)}),!1)}function Dt(t,e){switch(void 0===e&&(e=t.toString()),t.name){case"NotFoundError":return new Fe(be.ENOENT,e);case"QuotaExceededError":return new Fe(be.ENOSPC,e);default:return new Fe(be.EIO,e)}}function Pt(t,e,n){return void 0===e&&(e=be.EIO),void 0===n&&(n=null),function(r){r.preventDefault(),t(new Fe(e,null!==n?n:void 0))}}function Ct(t,e,n){return e?function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var r=e[0],i=this._getFs(r);e[0]=i.path;try{return i.fs[t].apply(i.fs,e)}catch(t){throw this.standardizeError(t,i.path,r),t}}:function(){for(var e=this,n=[],r=arguments.length;r--;)n[r]=arguments[r];var i=n[0],o=this._getFs(i);if(n[0]=o.path,"function"==typeof n[n.length-1]){var s=n[n.length-1];n[n.length-1]=function(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];t.length>0&&t[0]instanceof Fe&&e.standardizeError(t[0],o.path,i),s.apply(null,t)}}return o.fs[t].apply(o.fs,n)}}function Ut(t){return 146|t}function Mt(t){return Re.getFileFlag(t)}function jt(t){return{type:Wi.API_ERROR,errorData:Yt(t.writeToBuffer())}}function Bt(t){return Fe.fromBuffer(Xt(t.errorData))}function zt(t){return{type:Wi.ERROR,name:t.name,message:t.message,stack:t.stack}}function qt(t){var e=ti[t.name];"function"!=typeof e&&(e=Error);var n=new e(t.message);return n.stack=t.stack,n}function Vt(t){return{type:Wi.STATS,statsData:Yt(t.toBuffer())}}function Wt(t){return Te.fromBuffer(Xt(t.statsData))}function Ht(t){return{type:Wi.FILEFLAG,flagStr:t.getFlagString()}}function Zt(t){return Re.getFileFlag(t.flagStr)}function Yt(t){return v(t)}function Xt(t){return E(t)}function Kt(t){return{type:Wi.BUFFER,data:Yt(t)}}function Jt(t){return Xt(t.data)}function Gt(t){return t&&"object"==typeof t&&t.hasOwnProperty("browserfsMessage")&&t.browserfsMessage}function Qt(t){return t&&"object"==typeof t&&t.hasOwnProperty("browserfsMessage")&&t.browserfsMessage}function $t(e,n,r){var i=new XMLHttpRequest;i.open("GET",e,!0);var o=!0;switch(n){case"buffer":i.responseType="arraybuffer";break;case"json":try{i.responseType="json",o="json"===i.responseType}catch(t){o=!1}break;default:return r(new Fe(be.EINVAL,"Invalid download type: "+n))}i.onreadystatechange=function(e){if(4===i.readyState){if(200!==i.status)return r(new Fe(i.status,"XHR error."));switch(n){case"buffer":return r(null,i.response?t.from(i.response):S());case"json":return o?r(null,i.response):r(null,JSON.parse(i.responseText))}}},i.send()}function te(e,n){var r=new XMLHttpRequest;r.open("GET",e,!1);var i=null,o=null;if(r.overrideMimeType("text/plain; charset=x-user-defined"),r.onreadystatechange=function(e){if(4===r.readyState){if(200!==r.status)return void(o=new Fe(r.status,"XHR error."));switch(n){case"buffer":var s=r.responseText;i=t.alloc(s.length);for(var a=0;a<s.length;a++)i[a]=s.charCodeAt(a);return;case"json":return void(i=JSON.parse(r.responseText))}}},r.send(),o)throw o;return i}function ee(e,n){var r=new XMLHttpRequest;switch(r.open("GET",e,!1),n){case"buffer":r.responseType="arraybuffer";break;case"json":break;default:throw new Fe(be.EINVAL,"Invalid download type: "+n)}var i,o;if(r.onreadystatechange=function(e){if(4===r.readyState)if(200===r.status)switch(n){case"buffer":i=t.from(r.response);break;case"json":i=JSON.parse(r.response)}else o=new Fe(r.status,"XHR error.")},r.send(),o)throw o;return i}function ne(t,e,n){var r=new XMLHttpRequest;r.open("HEAD",e,t),r.onreadystatechange=function(t){if(4===r.readyState){if(200!==r.status)return n(new Fe(r.status,"XHR HEAD error."));try{return n(null,parseInt(r.getResponseHeader("Content-Length")||"-1",10))}catch(t){return n(new Fe(be.EIO,"XHR HEAD error: Could not read content-length."))}}},r.send()}function re(t){var e=-1;return ne(!1,t,function(t,n){if(t)throw t;e=n}),e}function ie(t,e){ne(!0,t,e)}function oe(t){return!!t&&t.isFile()}function se(t){return!!t&&t.isDir()}function ae(t,e,n){try{n(null,t.toString(e))}catch(t){n(t)}}function ce(t,e){var n=31&e,r=(e>>5&15)-1,i=(e>>9)+1980,o=31&t,s=t>>5&63,a=t>>11;return new Date(i,r,n,a,s,o)}function ue(t,e,n,r){return 0===r?"":e?t.toString("utf8",n,n+r):eo.byte2str(t.slice(n,n+r))}function fe(t,e,n){return t.toString("ascii",e,e+n).trim()}function he(t,e,n){if(1===n)return String.fromCharCode(t[e]);for(var r=Math.floor(n/2),i=new Array(r),o=0;o<r;o++){var s=e+(o<<1);i[o]=String.fromCharCode(t[s+1]|t[s]<<8)}return i.join("")}function pe(t,e){var n=parseInt(fe(t,e,4),10),r=parseInt(fe(t,e+4,2),10),i=parseInt(fe(t,e+6,2),10),o=parseInt(fe(t,e+8,2),10),s=parseInt(fe(t,e+10,2),10),a=parseInt(fe(t,e+12,2),10),c=parseInt(fe(t,e+14,2),10);return new Date(n,r,i,o,s,a,100*c)}function le(t,e){var n=t[e],r=t[e+1],i=t[e+2],o=t[e+3],s=t[e+4],a=t[e+5];return new Date(n,r-1,i,o,s,a)}function de(t,e){var n=t.slice(e),r=new ko(n);switch(r.signatureWord()){case 17221:return new Io(n);case 20548:return new Oo(n);case 21328:return new Fo(n);case 21332:return new No(n);case 17746:return new Ro(n);case 17747:return new Lo(n);case 20568:return new xo(n);case 20558:return new Ao(n);case 21324:return new Do(n);case 20045:return new Co(n);case 17228:return new Uo(n);case 20556:return new Mo(n);case 21061:return new jo(n);case 21574:return new Bo(n);case 21318:return new zo(n);case 21074:return new To(n);default:return r}}function ye(t,e,n,r){n-=4;for(var i=new Array;e<n;){var o=de(t,e),s=o.length();if(0===s)return i;if(e+=s,o instanceof No)break;o instanceof Io?i=i.concat(o.getEntries(r)):i.push(o)}return i}function ge(e){e.Buffer=t,e.process=o;var n=e.require?e.require:null;e.require=function(t){var e=me(t);return e?e:n.apply(null,Array.prototype.slice.call(arguments,0))}}function ve(t,e){Zo[t]=e}function me(t){switch(t){case"fs":return Pe;case"path":return ke;case"buffer":return Se;case"process":return o;case"bfs_utils":return Be;default:return Zo[t]}}function _e(t){return Pe.initialize(t)}function we(t,e){Ee(t,function(t,n){n?(_e(n),e()):e(t)})}function Ee(t,e){function n(){if(!s){s=!0;var t=Zo[r];t?t.Create(i,e):e(new Fe(be.EPERM,"File system "+r+" is not available in BrowserFS."))}}var r=t.fs;if(!r)return e(new Fe(be.EPERM,'Missing "fs" property on configuration object.'));var i=t.options,o=0,s=!1;if(null!==i&&"object"==typeof i){var a=!1,c=Object.keys(i).filter(function(t){return"fs"!==t});c.forEach(function(t){var r=i[t];null!==r&&"object"==typeof r&&r.fs&&(o++,Ee(r,function(r,c){if(o--,r){if(s)return;s=!0,e(r)}else i[t]=c,0===o&&a&&n()}))}),a=!0}0===o&&n()}Object.defineProperty(e,"__esModule",{value:!0});var be,Se=n(1),ke=n(14);!function(t){t[t.EPERM=1]="EPERM",t[t.ENOENT=2]="ENOENT",t[t.EIO=5]="EIO",t[t.EBADF=9]="EBADF",t[t.EACCES=13]="EACCES",t[t.EBUSY=16]="EBUSY",t[t.EEXIST=17]="EEXIST",t[t.ENOTDIR=20]="ENOTDIR",t[t.EISDIR=21]="EISDIR",t[t.EINVAL=22]="EINVAL",t[t.EFBIG=27]="EFBIG",t[t.ENOSPC=28]="ENOSPC",t[t.EROFS=30]="EROFS",t[t.ENOTEMPTY=39]="ENOTEMPTY",t[t.ENOTSUP=95]="ENOTSUP"}(be||(be={}));var Ie={};Ie[be.EPERM]="Operation not permitted.",Ie[be.ENOENT]="No such file or directory.",Ie[be.EIO]="Input/output error.",Ie[be.EBADF]="Bad file descriptor.",Ie[be.EACCES]="Permission denied.",Ie[be.EBUSY]="Resource busy or locked.",Ie[be.EEXIST]="File exists.",Ie[be.ENOTDIR]="File is not a directory.",Ie[be.EISDIR]="File is a directory.",Ie[be.EINVAL]="Invalid argument.",Ie[be.EFBIG]="File is too big.",Ie[be.ENOSPC]="No space left on disk.",Ie[be.EROFS]="Cannot modify a read-only file system.",Ie[be.ENOTEMPTY]="Directory is not empty.",Ie[be.ENOTSUP]="Operation is not supported.";var Oe,Fe=function(e){function n(t,n,r){void 0===n&&(n=Ie[t]),e.call(this,n),this.syscall="",this.errno=t,this.code=be[t],this.path=r,this.stack=(new e).stack,this.message="Error: "+this.code+": "+n+(this.path?", '"+this.path+"'":"")}return e&&(n.__proto__=e),n.prototype=Object.create(e&&e.prototype),n.prototype.constructor=n,n.fromJSON=function(t){var e=new n(0);return e.errno=t.errno,e.code=t.code,e.path=t.path,e.stack=t.stack,e.message=t.message,e},n.fromBuffer=function(t,e){return void 0===e&&(e=0),n.fromJSON(JSON.parse(t.toString("utf8",e+4,e+4+t.readUInt32LE(e))))},n.FileError=function(t,e){return new n(t,Ie[t],e)},n.ENOENT=function(t){return this.FileError(be.ENOENT,t)},n.EEXIST=function(t){return this.FileError(be.EEXIST,t)},n.EISDIR=function(t){return this.FileError(be.EISDIR,t)},n.ENOTDIR=function(t){return this.FileError(be.ENOTDIR,t)},n.EPERM=function(t){return this.FileError(be.EPERM,t)},n.ENOTEMPTY=function(t){return this.FileError(be.ENOTEMPTY,t)},n.prototype.toString=function(){return this.message},n.prototype.toJSON=function(){return{errno:this.errno,code:this.code,path:this.path,stack:this.stack,message:this.message}},n.prototype.writeToBuffer=function(e,n){void 0===e&&(e=t.alloc(this.bufferSize())),void 0===n&&(n=0);var r=e.write(JSON.stringify(this.toJSON()),n+4);return e.writeUInt32LE(r,n),e},n.prototype.bufferSize=function(){return 4+t.byteLength(JSON.stringify(this.toJSON()))},n}(Error),Ne=Object.freeze({get ErrorCode(){return be},ErrorStrings:Ie,ApiError:Fe});!function(t){t[t.NOP=0]="NOP",t[t.THROW_EXCEPTION=1]="THROW_EXCEPTION",t[t.TRUNCATE_FILE=2]="TRUNCATE_FILE",t[t.CREATE_FILE=3]="CREATE_FILE"}(Oe||(Oe={}));var Re=function t(e){if(this.flagStr=e,t.validFlagStrs.indexOf(e)<0)throw new Fe(be.EINVAL,"Invalid flag: "+e)};Re.getFileFlag=function(t){return Re.flagCache.hasOwnProperty(t)?Re.flagCache[t]:Re.flagCache[t]=new Re(t)},Re.prototype.getFlagString=function(){return this.flagStr},Re.prototype.isReadable=function(){return this.flagStr.indexOf("r")!==-1||this.flagStr.indexOf("+")!==-1},Re.prototype.isWriteable=function(){return this.flagStr.indexOf("w")!==-1||this.flagStr.indexOf("a")!==-1||this.flagStr.indexOf("+")!==-1},Re.prototype.isTruncating=function(){return this.flagStr.indexOf("w")!==-1},Re.prototype.isAppendable=function(){return this.flagStr.indexOf("a")!==-1},Re.prototype.isSynchronous=function(){return this.flagStr.indexOf("s")!==-1},Re.prototype.isExclusive=function(){return this.flagStr.indexOf("x")!==-1},Re.prototype.pathExistsAction=function(){return this.isExclusive()?Oe.THROW_EXCEPTION:this.isTruncating()?Oe.TRUNCATE_FILE:Oe.NOP},Re.prototype.pathNotExistsAction=function(){return(this.isWriteable()||this.isAppendable())&&"r+"!==this.flagStr?Oe.CREATE_FILE:Oe.THROW_EXCEPTION},Re.flagCache={},Re.validFlagStrs=["r","r+","rs","rs+","w","wx","w+","wx+","a","ax","a+","ax+"];var Le;!function(t){t[t.FILE=32768]="FILE",t[t.DIRECTORY=16384]="DIRECTORY",t[t.SYMLINK=40960]="SYMLINK"}(Le||(Le={}));var Te=function(t,e,n,r,i,o){if(void 0===r&&(r=new Date),void 0===i&&(i=new Date),void 0===o&&(o=new Date),this.size=e,this.atime=r,this.mtime=i,this.ctime=o,this.dev=0,this.ino=0,this.rdev=0,this.nlink=1,this.blksize=4096,this.uid=0,this.gid=0,this.birthtime=new Date(0),this.fileData=null,n)this.mode=n;else switch(t){case Le.FILE:this.mode=420;break;case Le.DIRECTORY:default:this.mode=511}this.blocks=Math.ceil(e/512),this.mode<4096&&(this.mode|=t)};Te.fromBuffer=function(t){var e=t.readUInt32LE(0),n=t.readUInt32LE(4),r=t.readDoubleLE(8),i=t.readDoubleLE(16),o=t.readDoubleLE(24);return new Te(61440&n,e,4095&n,new Date(r),new Date(i),new Date(o))},Te.prototype.toBuffer=function(){var e=t.alloc(32);return e.writeUInt32LE(this.size,0),e.writeUInt32LE(this.mode,4),e.writeDoubleLE(this.atime.getTime(),8),e.writeDoubleLE(this.mtime.getTime(),16),e.writeDoubleLE(this.ctime.getTime(),24),e},Te.prototype.clone=function(){return new Te(61440&this.mode,this.size,4095&this.mode,this.atime,this.mtime,this.ctime)},Te.prototype.isFile=function(){return(61440&this.mode)===Le.FILE},Te.prototype.isDirectory=function(){return(61440&this.mode)===Le.DIRECTORY},Te.prototype.isSymbolicLink=function(){return(61440&this.mode)===Le.SYMLINK},Te.prototype.chmod=function(t){this.mode=61440&this.mode|t},Te.prototype.isSocket=function(){return!1},Te.prototype.isBlockDevice=function(){return!1},Te.prototype.isCharacterDevice=function(){return!1},Te.prototype.isFIFO=function(){return!1};var xe=function(t,e){return t},Ae=function(){this.F_OK=0,this.R_OK=4,this.W_OK=2,this.X_OK=1,this.root=null,this.fdMap={},this.nextFd=100};Ae.prototype.initialize=function(t){if(!t.constructor.isAvailable())throw new Fe(be.EINVAL,"Tried to instantiate BrowserFS with an unavailable file system.");return this.root=t},Ae.prototype._toUnixTimestamp=function(t){if("number"==typeof t)return t;if(t instanceof Date)return t.getTime()/1e3;throw new Error("Cannot parse time: "+t)},Ae.prototype.getRootFS=function(){return this.root?this.root:null},Ae.prototype.rename=function(t,e,n){void 0===n&&(n=h);var r=xe(n,1);try{s(this.root).rename(u(t),u(e),r)}catch(t){r(t)}},Ae.prototype.renameSync=function(t,e){s(this.root).renameSync(u(t),u(e))},Ae.prototype.exists=function(t,e){void 0===e&&(e=h);var n=xe(e,1);try{return s(this.root).exists(u(t),n)}catch(t){return n(!1)}},Ae.prototype.existsSync=function(t){try{return s(this.root).existsSync(u(t))}catch(t){return!1}},Ae.prototype.stat=function(t,e){void 0===e&&(e=h);var n=xe(e,2);try{return s(this.root).stat(u(t),!1,n)}catch(t){return n(t)}},Ae.prototype.statSync=function(t){return s(this.root).statSync(u(t),!1)},Ae.prototype.lstat=function(t,e){void 0===e&&(e=h);var n=xe(e,2);try{return s(this.root).stat(u(t),!0,n)}catch(t){return n(t)}},Ae.prototype.lstatSync=function(t){return s(this.root).statSync(u(t),!0)},Ae.prototype.truncate=function(t,e,n){void 0===e&&(e=0),void 0===n&&(n=h);var r=0;"function"==typeof e?n=e:"number"==typeof e&&(r=e);var i=xe(n,1);try{if(r<0)throw new Fe(be.EINVAL);return s(this.root).truncate(u(t),r,i)}catch(t){return i(t)}},Ae.prototype.truncateSync=function(t,e){if(void 0===e&&(e=0),e<0)throw new Fe(be.EINVAL);return s(this.root).truncateSync(u(t),e)},Ae.prototype.unlink=function(t,e){void 0===e&&(e=h);var n=xe(e,1);try{return s(this.root).unlink(u(t),n)}catch(t){return n(t)}},Ae.prototype.unlinkSync=function(t){return s(this.root).unlinkSync(u(t))},Ae.prototype.open=function(t,e,n,r){var i=this;void 0===r&&(r=h);var o=a(n,420);r="function"==typeof n?n:r;var c=xe(r,2);try{s(this.root).open(u(t),Re.getFileFlag(e),o,function(t,e){e?c(t,i.getFdForFile(e)):c(t)})}catch(t){c(t)}},Ae.prototype.openSync=function(t,e,n){return void 0===n&&(n=420),this.getFdForFile(s(this.root).openSync(u(t),Re.getFileFlag(e),a(n,420)))},Ae.prototype.readFile=function(t,e,n){void 0===e&&(e={}),void 0===n&&(n=h);var r=f(e,null,"r",null);n="function"==typeof e?e:n;var i=xe(n,2);try{var o=Re.getFileFlag(r.flag);return o.isReadable()?s(this.root).readFile(u(t),r.encoding,o,i):i(new Fe(be.EINVAL,"Flag passed to readFile must allow for reading."))}catch(t){return i(t)}},Ae.prototype.readFileSync=function(t,e){void 0===e&&(e={});var n=f(e,null,"r",null),r=Re.getFileFlag(n.flag);if(!r.isReadable())throw new Fe(be.EINVAL,"Flag passed to readFile must allow for reading.");return s(this.root).readFileSync(u(t),n.encoding,r)},Ae.prototype.writeFile=function(t,e,n,r){void 0===n&&(n={}),void 0===r&&(r=h);var i=f(n,"utf8","w",420);r="function"==typeof n?n:r;var o=xe(r,1);try{var a=Re.getFileFlag(i.flag);return a.isWriteable()?s(this.root).writeFile(u(t),e,i.encoding,a,i.mode,o):o(new Fe(be.EINVAL,"Flag passed to writeFile must allow for writing."))}catch(t){return o(t)}},Ae.prototype.writeFileSync=function(t,e,n){var r=f(n,"utf8","w",420),i=Re.getFileFlag(r.flag);if(!i.isWriteable())throw new Fe(be.EINVAL,"Flag passed to writeFile must allow for writing.");return s(this.root).writeFileSync(u(t),e,r.encoding,i,r.mode)},Ae.prototype.appendFile=function(t,e,n,r){void 0===r&&(r=h);var i=f(n,"utf8","a",420);r="function"==typeof n?n:r;var o=xe(r,1);try{var a=Re.getFileFlag(i.flag);if(!a.isAppendable())return o(new Fe(be.EINVAL,"Flag passed to appendFile must allow for appending."));s(this.root).appendFile(u(t),e,i.encoding,a,i.mode,o)}catch(t){o(t)}},Ae.prototype.appendFileSync=function(t,e,n){var r=f(n,"utf8","a",420),i=Re.getFileFlag(r.flag);if(!i.isAppendable())throw new Fe(be.EINVAL,"Flag passed to appendFile must allow for appending.");return s(this.root).appendFileSync(u(t),e,r.encoding,i,r.mode)},Ae.prototype.fstat=function(t,e){void 0===e&&(e=h);var n=xe(e,2);try{var r=this.fd2file(t);r.stat(n)}catch(t){n(t)}},Ae.prototype.fstatSync=function(t){return this.fd2file(t).statSync()},Ae.prototype.close=function(t,e){var n=this;void 0===e&&(e=h);var r=xe(e,1);try{this.fd2file(t).close(function(e){e||n.closeFd(t),r(e)})}catch(t){r(t)}},Ae.prototype.closeSync=function(t){this.fd2file(t).closeSync(),this.closeFd(t)},Ae.prototype.ftruncate=function(t,e,n){void 0===n&&(n=h);var r="number"==typeof e?e:0;n="function"==typeof e?e:n;var i=xe(n,1);try{var o=this.fd2file(t);if(r<0)throw new Fe(be.EINVAL);o.truncate(r,i)}catch(t){i(t)}},Ae.prototype.ftruncateSync=function(t,e){void 0===e&&(e=0);var n=this.fd2file(t);if(e<0)throw new Fe(be.EINVAL);n.truncateSync(e)},Ae.prototype.fsync=function(t,e){void 0===e&&(e=h);var n=xe(e,1);try{this.fd2file(t).sync(n)}catch(t){n(t)}},Ae.prototype.fsyncSync=function(t){this.fd2file(t).syncSync()},Ae.prototype.fdatasync=function(t,e){void 0===e&&(e=h);var n=xe(e,1);try{this.fd2file(t).datasync(n)}catch(t){n(t)}},Ae.prototype.fdatasyncSync=function(t){this.fd2file(t).datasyncSync()},Ae.prototype.write=function(e,n,r,i,o,s){void 0===s&&(s=h);var a,c,u,f=null;if("string"==typeof n){var p="utf8";switch(typeof r){case"function":s=r;break;case"number":f=r,p="string"==typeof i?i:"utf8",s="function"==typeof o?o:s;break;default:return(s="function"==typeof i?i:"function"==typeof o?o:s)(new Fe(be.EINVAL,"Invalid arguments."))}a=t.from(n,p),c=0,u=a.length}else a=n,c=r,u=i,f="number"==typeof o?o:null,s="function"==typeof o?o:s;var l=xe(s,3);try{var d=this.fd2file(e);void 0!==f&&null!==f||(f=d.getPos()),d.write(a,c,u,f,l)}catch(t){l(t)}},Ae.prototype.writeSync=function(e,n,r,i,o){var s,a,c,u=0;if("string"==typeof n){c="number"==typeof r?r:null;var f="string"==typeof i?i:"utf8";u=0,s=t.from(n,f),a=s.length}else s=n,u=r,a=i,c="number"==typeof o?o:null;var h=this.fd2file(e);return void 0!==c&&null!==c||(c=h.getPos()),h.writeSync(s,u,a,c)},Ae.prototype.read=function(e,n,r,i,o,s){void 0===s&&(s=h);var a,c,u,f,p;if("number"==typeof n){u=n,a=r;var l=i;s="function"==typeof o?o:s,c=0,f=t.alloc(u),p=xe(function(t,e,n){return t?s(t):void s(t,n.toString(l),e)},3)}else f=n,c=r,u=i,a=o,p=xe(s,3);try{var d=this.fd2file(e);void 0!==a&&null!==a||(a=d.getPos()),d.read(f,c,u,a,p)}catch(t){p(t)}},Ae.prototype.readSync=function(e,n,r,i,o){var s,a,c,u,f=!1,h="utf8";"number"==typeof n?(c=n,u=r,h=i,a=0,s=t.alloc(c),f=!0):(s=n,a=r,c=i,u=o);var p=this.fd2file(e);void 0!==u&&null!==u||(u=p.getPos());var l=p.readSync(s,a,c,u);return f?[s.toString(h),l]:l},Ae.prototype.fchown=function(t,e,n,r){void 0===r&&(r=h);var i=xe(r,1);try{this.fd2file(t).chown(e,n,i)}catch(t){i(t)}},Ae.prototype.fchownSync=function(t,e,n){this.fd2file(t).chownSync(e,n)},Ae.prototype.fchmod=function(t,e,n){var r=xe(n,1);try{var i="string"==typeof e?parseInt(e,8):e;this.fd2file(t).chmod(i,r)}catch(t){r(t)}},Ae.prototype.fchmodSync=function(t,e){var n="string"==typeof e?parseInt(e,8):e;this.fd2file(t).chmodSync(n)},Ae.prototype.futimes=function(t,e,n,r){void 0===r&&(r=h);var i=xe(r,1);try{var o=this.fd2file(t);"number"==typeof e&&(e=new Date(1e3*e)),"number"==typeof n&&(n=new Date(1e3*n)),o.utimes(e,n,i)}catch(t){i(t)}},Ae.prototype.futimesSync=function(t,e,n){this.fd2file(t).utimesSync(c(e),c(n))},Ae.prototype.rmdir=function(t,e){void 0===e&&(e=h);var n=xe(e,1);try{t=u(t),s(this.root).rmdir(t,n)}catch(t){n(t)}},Ae.prototype.rmdirSync=function(t){return t=u(t),s(this.root).rmdirSync(t)},Ae.prototype.mkdir=function(t,e,n){void 0===n&&(n=h),"function"==typeof e&&(n=e,e=511);var r=xe(n,1);try{t=u(t),s(this.root).mkdir(t,e,r)}catch(t){r(t)}},Ae.prototype.mkdirSync=function(t,e){s(this.root).mkdirSync(u(t),a(e,511))},Ae.prototype.readdir=function(t,e){void 0===e&&(e=h);var n=xe(e,2);try{t=u(t),s(this.root).readdir(t,n)}catch(t){n(t)}},Ae.prototype.readdirSync=function(t){return t=u(t),s(this.root).readdirSync(t)},Ae.prototype.link=function(t,e,n){void 0===n&&(n=h);var r=xe(n,1);try{t=u(t),e=u(e),s(this.root).link(t,e,r)}catch(t){r(t)}},Ae.prototype.linkSync=function(t,e){return t=u(t),e=u(e),s(this.root).linkSync(t,e)},Ae.prototype.symlink=function(t,e,n,r){void 0===r&&(r=h);var i="string"==typeof n?n:"file";r="function"==typeof n?n:r;var o=xe(r,1);try{if("file"!==i&&"dir"!==i)return o(new Fe(be.EINVAL,"Invalid type: "+i));t=u(t),e=u(e),s(this.root).symlink(t,e,i,o)}catch(t){o(t)}},Ae.prototype.symlinkSync=function(t,e,n){ if(n){if("file"!==n&&"dir"!==n)throw new Fe(be.EINVAL,"Invalid type: "+n)}else n="file";return t=u(t),e=u(e),s(this.root).symlinkSync(t,e,n)},Ae.prototype.readlink=function(t,e){void 0===e&&(e=h);var n=xe(e,2);try{t=u(t),s(this.root).readlink(t,n)}catch(t){n(t)}},Ae.prototype.readlinkSync=function(t){return t=u(t),s(this.root).readlinkSync(t)},Ae.prototype.chown=function(t,e,n,r){void 0===r&&(r=h);var i=xe(r,1);try{t=u(t),s(this.root).chown(t,!1,e,n,i)}catch(t){i(t)}},Ae.prototype.chownSync=function(t,e,n){t=u(t),s(this.root).chownSync(t,!1,e,n)},Ae.prototype.lchown=function(t,e,n,r){void 0===r&&(r=h);var i=xe(r,1);try{t=u(t),s(this.root).chown(t,!0,e,n,i)}catch(t){i(t)}},Ae.prototype.lchownSync=function(t,e,n){t=u(t),s(this.root).chownSync(t,!0,e,n)},Ae.prototype.chmod=function(t,e,n){void 0===n&&(n=h);var r=xe(n,1);try{var i=a(e,-1);if(i<0)throw new Fe(be.EINVAL,"Invalid mode.");s(this.root).chmod(u(t),!1,i,r)}catch(t){r(t)}},Ae.prototype.chmodSync=function(t,e){var n=a(e,-1);if(n<0)throw new Fe(be.EINVAL,"Invalid mode.");t=u(t),s(this.root).chmodSync(t,!1,n)},Ae.prototype.lchmod=function(t,e,n){void 0===n&&(n=h);var r=xe(n,1);try{var i=a(e,-1);if(i<0)throw new Fe(be.EINVAL,"Invalid mode.");s(this.root).chmod(u(t),!0,i,r)}catch(t){r(t)}},Ae.prototype.lchmodSync=function(t,e){var n=a(e,-1);if(n<1)throw new Fe(be.EINVAL,"Invalid mode.");s(this.root).chmodSync(u(t),!0,n)},Ae.prototype.utimes=function(t,e,n,r){void 0===r&&(r=h);var i=xe(r,1);try{s(this.root).utimes(u(t),c(e),c(n),i)}catch(t){i(t)}},Ae.prototype.utimesSync=function(t,e,n){s(this.root).utimesSync(u(t),c(e),c(n))},Ae.prototype.realpath=function(t,e,n){void 0===n&&(n=h);var r="object"==typeof e?e:{};n="function"==typeof e?e:h;var i=xe(n,2);try{t=u(t),s(this.root).realpath(t,r,i)}catch(t){i(t)}},Ae.prototype.realpathSync=function(t,e){return void 0===e&&(e={}),t=u(t),s(this.root).realpathSync(t,e)},Ae.prototype.watchFile=function(t,e,n){throw void 0===n&&(n=h),new Fe(be.ENOTSUP)},Ae.prototype.unwatchFile=function(t,e){throw void 0===e&&(e=h),new Fe(be.ENOTSUP)},Ae.prototype.watch=function(t,e,n){throw void 0===n&&(n=h),new Fe(be.ENOTSUP)},Ae.prototype.access=function(t,e,n){throw void 0===n&&(n=h),new Fe(be.ENOTSUP)},Ae.prototype.accessSync=function(t,e){throw new Fe(be.ENOTSUP)},Ae.prototype.createReadStream=function(t,e){throw new Fe(be.ENOTSUP)},Ae.prototype.createWriteStream=function(t,e){throw new Fe(be.ENOTSUP)},Ae.prototype.wrapCallbacks=function(t){xe=t},Ae.prototype.getFdForFile=function(t){var e=this.nextFd++;return this.fdMap[e]=t,e},Ae.prototype.fd2file=function(t){var e=this.fdMap[t];if(e)return e;throw new Fe(be.EBADF,"Invalid file descriptor.")},Ae.prototype.closeFd=function(t){delete this.fdMap[t]},Ae.Stats=Te;var De=new Ae,Pe={},Ce=Ae.prototype;Object.keys(Ce).forEach(function(t){"function"==typeof De[t]?Pe[t]=function(){return De[t].apply(De,arguments)}:Pe[t]=De[t]}),Pe.changeFSModule=function(t){De=t},Pe.getFSModule=function(){return De},Pe.FS=Ae;var Ue="undefined"!=typeof navigator&&!(!/(msie) ([\w.]+)/.exec(navigator.userAgent.toLowerCase())&&navigator.userAgent.indexOf("Trident")===-1),Me="undefined"==typeof window,je=null,Be=Object.freeze({deprecationMessage:d,isIE:Ue,isWebWorker:Me,fail:y,mkdirpSync:g,buffer2ArrayBuffer:v,buffer2Uint8array:m,arrayish2Buffer:_,uint8Array2Buffer:w,arrayBuffer2Buffer:E,copyingSlice:b,emptyBuffer:S,bufferValidator:k,checkOptions:I}),ze=function(t){this.fs=t,this.nodefs=t.getNodeFS(),this.FS=t.getFS(),this.PATH=t.getPATH(),this.ERRNO_CODES=t.getERRNO_CODES()};ze.prototype.open=function(t){var e=this.fs.realPath(t.node),n=this.FS;try{n.isFile(t.node.mode)&&(t.nfd=this.nodefs.openSync(e,this.fs.flagsToPermissionString(t.flags)))}catch(t){if(!t.code)throw t;throw new n.ErrnoError(this.ERRNO_CODES[t.code])}},ze.prototype.close=function(t){var e=this.FS;try{e.isFile(t.node.mode)&&t.nfd&&this.nodefs.closeSync(t.nfd)}catch(t){if(!t.code)throw t;throw new e.ErrnoError(this.ERRNO_CODES[t.code])}},ze.prototype.read=function(t,e,n,r,i){try{return this.nodefs.readSync(t.nfd,w(e),n,r,i)}catch(t){throw new this.FS.ErrnoError(this.ERRNO_CODES[t.code])}},ze.prototype.write=function(t,e,n,r,i){try{return this.nodefs.writeSync(t.nfd,w(e),n,r,i)}catch(t){throw new this.FS.ErrnoError(this.ERRNO_CODES[t.code])}},ze.prototype.llseek=function(t,e,n){var r=e;if(1===n)r+=t.position;else if(2===n&&this.FS.isFile(t.node.mode))try{var i=this.nodefs.fstatSync(t.nfd);r+=i.size}catch(t){throw new this.FS.ErrnoError(this.ERRNO_CODES[t.code])}if(r<0)throw new this.FS.ErrnoError(this.ERRNO_CODES.EINVAL);return t.position=r,r};var qe=function(t){this.fs=t,this.nodefs=t.getNodeFS(),this.FS=t.getFS(),this.PATH=t.getPATH(),this.ERRNO_CODES=t.getERRNO_CODES()};qe.prototype.getattr=function(t){var e,n=this.fs.realPath(t);try{e=this.nodefs.lstatSync(n)}catch(t){if(!t.code)throw t;throw new this.FS.ErrnoError(this.ERRNO_CODES[t.code])}return{dev:e.dev,ino:e.ino,mode:e.mode,nlink:e.nlink,uid:e.uid,gid:e.gid,rdev:e.rdev,size:e.size,atime:e.atime,mtime:e.mtime,ctime:e.ctime,blksize:e.blksize,blocks:e.blocks}},qe.prototype.setattr=function(t,e){var n=this.fs.realPath(t);try{if(void 0!==e.mode&&(this.nodefs.chmodSync(n,e.mode),t.mode=e.mode),void 0!==e.timestamp){var r=new Date(e.timestamp);this.nodefs.utimesSync(n,r,r)}}catch(t){if(!t.code)throw t;if("ENOTSUP"!==t.code)throw new this.FS.ErrnoError(this.ERRNO_CODES[t.code])}if(void 0!==e.size)try{this.nodefs.truncateSync(n,e.size)}catch(t){if(!t.code)throw t;throw new this.FS.ErrnoError(this.ERRNO_CODES[t.code])}},qe.prototype.lookup=function(t,e){var n=this.PATH.join2(this.fs.realPath(t),e),r=this.fs.getMode(n);return this.fs.createNode(t,e,r)},qe.prototype.mknod=function(t,e,n,r){var i=this.fs.createNode(t,e,n,r),o=this.fs.realPath(i);try{this.FS.isDir(i.mode)?this.nodefs.mkdirSync(o,i.mode):this.nodefs.writeFileSync(o,"",{mode:i.mode})}catch(t){if(!t.code)throw t;throw new this.FS.ErrnoError(this.ERRNO_CODES[t.code])}return i},qe.prototype.rename=function(t,e,n){var r=this.fs.realPath(t),i=this.PATH.join2(this.fs.realPath(e),n);try{this.nodefs.renameSync(r,i),t.name=n,t.parent=e}catch(t){if(!t.code)throw t;throw new this.FS.ErrnoError(this.ERRNO_CODES[t.code])}},qe.prototype.unlink=function(t,e){var n=this.PATH.join2(this.fs.realPath(t),e);try{this.nodefs.unlinkSync(n)}catch(t){if(!t.code)throw t;throw new this.FS.ErrnoError(this.ERRNO_CODES[t.code])}},qe.prototype.rmdir=function(t,e){var n=this.PATH.join2(this.fs.realPath(t),e);try{this.nodefs.rmdirSync(n)}catch(t){if(!t.code)throw t;throw new this.FS.ErrnoError(this.ERRNO_CODES[t.code])}},qe.prototype.readdir=function(t){var e=this.fs.realPath(t);try{var n=this.nodefs.readdirSync(e);return n.push(".",".."),n}catch(t){if(!t.code)throw t;throw new this.FS.ErrnoError(this.ERRNO_CODES[t.code])}},qe.prototype.symlink=function(t,e,n){var r=this.PATH.join2(this.fs.realPath(t),e);try{this.nodefs.symlinkSync(n,r)}catch(t){if(!t.code)throw t;throw new this.FS.ErrnoError(this.ERRNO_CODES[t.code])}},qe.prototype.readlink=function(t){var e=this.fs.realPath(t);try{return this.nodefs.readlinkSync(e)}catch(t){if(!t.code)throw t;throw new this.FS.ErrnoError(this.ERRNO_CODES[t.code])}};var Ve=function(t,e,n,r){void 0===t&&(t=self.FS),void 0===e&&(e=self.PATH),void 0===n&&(n=self.ERRNO_CODES),void 0===r&&(r=Pe),this.flagsToPermissionStringMap={0:"r",1:"r+",2:"r+",64:"r",65:"r+",66:"r+",129:"rx+",193:"rx+",514:"w+",577:"w",578:"w+",705:"wx",706:"wx+",1024:"a",1025:"a",1026:"a+",1089:"a",1090:"a+",1153:"ax",1154:"ax+",1217:"ax",1218:"ax+",4096:"rs",4098:"rs+"},this.nodefs=r,this.FS=t,this.PATH=e,this.ERRNO_CODES=n,this.node_ops=new qe(this),this.stream_ops=new ze(this)};Ve.prototype.mount=function(t){return this.createNode(null,"/",this.getMode(t.opts.root),0)},Ve.prototype.createNode=function(t,e,n,r){var i=this.FS;if(!i.isDir(n)&&!i.isFile(n)&&!i.isLink(n))throw new i.ErrnoError(this.ERRNO_CODES.EINVAL);var o=i.createNode(t,e,n);return o.node_ops=this.node_ops,o.stream_ops=this.stream_ops,o},Ve.prototype.getMode=function(t){var e;try{e=this.nodefs.lstatSync(t)}catch(t){if(!t.code)throw t;throw new this.FS.ErrnoError(this.ERRNO_CODES[t.code])}return e.mode},Ve.prototype.realPath=function(t){for(var e=[];t.parent!==t;)e.push(t.name),t=t.parent;return e.push(t.mount.opts.root),e.reverse(),this.PATH.join.apply(null,e)},Ve.prototype.flagsToPermissionString=function(t){var e="string"==typeof t?parseInt(t,10):t;return e&=8191,e in this.flagsToPermissionStringMap?this.flagsToPermissionStringMap[e]:t},Ve.prototype.getNodeFS=function(){return this.nodefs},Ve.prototype.getFS=function(){return this.FS},Ve.prototype.getPATH=function(){return this.PATH},Ve.prototype.getERRNO_CODES=function(){return this.ERRNO_CODES};var We=function(){};We.prototype.supportsLinks=function(){return!1},We.prototype.diskSpace=function(t,e){e(0,0)},We.prototype.openFile=function(t,e,n){throw new Fe(be.ENOTSUP)},We.prototype.createFile=function(t,e,n,r){throw new Fe(be.ENOTSUP)},We.prototype.open=function(t,e,n,r){var i=this,o=function(o,s){if(o)switch(e.pathNotExistsAction()){case Oe.CREATE_FILE:return i.stat(ke.dirname(t),!1,function(o,s){o?r(o):s&&!s.isDirectory()?r(Fe.ENOTDIR(ke.dirname(t))):i.createFile(t,e,n,r)});case Oe.THROW_EXCEPTION:return r(Fe.ENOENT(t));default:return r(new Fe(be.EINVAL,"Invalid FileFlag object."))}else{if(s&&s.isDirectory())return r(Fe.EISDIR(t));switch(e.pathExistsAction()){case Oe.THROW_EXCEPTION:return r(Fe.EEXIST(t));case Oe.TRUNCATE_FILE:return i.openFile(t,e,function(t,e){t?r(t):e?e.truncate(0,function(){e.sync(function(){r(null,e)})}):y()});case Oe.NOP:return i.openFile(t,e,r);default:return r(new Fe(be.EINVAL,"Invalid FileFlag object."))}}};this.stat(t,!1,o)},We.prototype.rename=function(t,e,n){n(new Fe(be.ENOTSUP))},We.prototype.renameSync=function(t,e){throw new Fe(be.ENOTSUP)},We.prototype.stat=function(t,e,n){n(new Fe(be.ENOTSUP))},We.prototype.statSync=function(t,e){throw new Fe(be.ENOTSUP)},We.prototype.openFileSync=function(t,e,n){throw new Fe(be.ENOTSUP)},We.prototype.createFileSync=function(t,e,n){throw new Fe(be.ENOTSUP)},We.prototype.openSync=function(t,e,n){var r;try{r=this.statSync(t,!1)}catch(r){switch(e.pathNotExistsAction()){case Oe.CREATE_FILE:var i=this.statSync(ke.dirname(t),!1);if(!i.isDirectory())throw Fe.ENOTDIR(ke.dirname(t));return this.createFileSync(t,e,n);case Oe.THROW_EXCEPTION:throw Fe.ENOENT(t);default:throw new Fe(be.EINVAL,"Invalid FileFlag object.")}}if(r.isDirectory())throw Fe.EISDIR(t);switch(e.pathExistsAction()){case Oe.THROW_EXCEPTION:throw Fe.EEXIST(t);case Oe.TRUNCATE_FILE:return this.unlinkSync(t),this.createFileSync(t,e,r.mode);case Oe.NOP:return this.openFileSync(t,e,n);default:throw new Fe(be.EINVAL,"Invalid FileFlag object.")}},We.prototype.unlink=function(t,e){e(new Fe(be.ENOTSUP))},We.prototype.unlinkSync=function(t){throw new Fe(be.ENOTSUP)},We.prototype.rmdir=function(t,e){e(new Fe(be.ENOTSUP))},We.prototype.rmdirSync=function(t){throw new Fe(be.ENOTSUP)},We.prototype.mkdir=function(t,e,n){n(new Fe(be.ENOTSUP))},We.prototype.mkdirSync=function(t,e){throw new Fe(be.ENOTSUP)},We.prototype.readdir=function(t,e){e(new Fe(be.ENOTSUP))},We.prototype.readdirSync=function(t){throw new Fe(be.ENOTSUP)},We.prototype.exists=function(t,e){this.stat(t,null,function(t){e(!t)})},We.prototype.existsSync=function(t){try{return this.statSync(t,!0),!0}catch(t){return!1}},We.prototype.realpath=function(t,e,n){if(this.supportsLinks())for(var r=t.split(ke.sep),i=0;i<r.length;i++){var o=r.slice(0,i+1);r[i]=ke.join.apply(null,o)}else this.exists(t,function(e){e?n(null,t):n(Fe.ENOENT(t))})},We.prototype.realpathSync=function(t,e){if(this.supportsLinks()){for(var n=t.split(ke.sep),r=0;r<n.length;r++){var i=n.slice(0,r+1);n[r]=ke.join.apply(ke,i)}return n.join(ke.sep)}if(this.existsSync(t))return t;throw Fe.ENOENT(t)},We.prototype.truncate=function(t,e,n){this.open(t,Re.getFileFlag("r+"),420,function(t,r){return t?n(t):void r.truncate(e,function(t){r.close(function(e){n(t||e)})})})},We.prototype.truncateSync=function(t,e){var n=this.openSync(t,Re.getFileFlag("r+"),420);try{n.truncateSync(e)}catch(t){throw t}finally{n.closeSync()}},We.prototype.readFile=function(e,n,r,i){var o=i;this.open(e,r,420,function(e,r){return e?i(e):(i=function(t,e){r.close(function(n){return t||(t=n),o(t,e)})},void r.stat(function(e,o){if(e)return i(e);var s=t.alloc(o.size);r.read(s,0,o.size,0,function(t){if(t)return i(t);if(null===n)return i(t,s);try{i(null,s.toString(n))}catch(t){i(t)}})}))})},We.prototype.readFileSync=function(e,n,r){var i=this.openSync(e,r,420);try{var o=i.statSync(),s=t.alloc(o.size);return i.readSync(s,0,o.size,0),i.closeSync(),null===n?s:s.toString(n)}finally{i.closeSync()}},We.prototype.writeFile=function(e,n,r,i,o,s){var a=s;this.open(e,i,420,function(e,i){if(e)return s(e);s=function(t){i.close(function(e){a(t?t:e)})};try{"string"==typeof n&&(n=t.from(n,r))}catch(t){return s(t)}i.write(n,0,n.length,0,s)})},We.prototype.writeFileSync=function(e,n,r,i,o){var s=this.openSync(e,i,o);try{"string"==typeof n&&(n=t.from(n,r)),s.writeSync(n,0,n.length,0)}finally{s.closeSync()}},We.prototype.appendFile=function(e,n,r,i,o,s){var a=s;this.open(e,i,o,function(e,i){return e?s(e):(s=function(t){i.close(function(e){a(t?t:e)})},"string"==typeof n&&(n=t.from(n,r)),void i.write(n,0,n.length,null,s))})},We.prototype.appendFileSync=function(e,n,r,i,o){var s=this.openSync(e,i,o);try{"string"==typeof n&&(n=t.from(n,r)),s.writeSync(n,0,n.length,null)}finally{s.closeSync()}},We.prototype.chmod=function(t,e,n,r){r(new Fe(be.ENOTSUP))},We.prototype.chmodSync=function(t,e,n){throw new Fe(be.ENOTSUP)},We.prototype.chown=function(t,e,n,r,i){i(new Fe(be.ENOTSUP))},We.prototype.chownSync=function(t,e,n,r){throw new Fe(be.ENOTSUP)},We.prototype.utimes=function(t,e,n,r){r(new Fe(be.ENOTSUP))},We.prototype.utimesSync=function(t,e,n){throw new Fe(be.ENOTSUP)},We.prototype.link=function(t,e,n){n(new Fe(be.ENOTSUP))},We.prototype.linkSync=function(t,e){throw new Fe(be.ENOTSUP)},We.prototype.symlink=function(t,e,n,r){r(new Fe(be.ENOTSUP))},We.prototype.symlinkSync=function(t,e,n){throw new Fe(be.ENOTSUP)},We.prototype.readlink=function(t,e){e(new Fe(be.ENOTSUP))},We.prototype.readlinkSync=function(t){throw new Fe(be.ENOTSUP)};var He=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.supportsSynch=function(){return!0},e.prototype.rename=function(t,e,n){try{this.renameSync(t,e),n()}catch(t){n(t)}},e.prototype.stat=function(t,e,n){try{n(null,this.statSync(t,e))}catch(t){n(t)}},e.prototype.open=function(t,e,n,r){try{r(null,this.openSync(t,e,n))}catch(t){r(t)}},e.prototype.unlink=function(t,e){try{this.unlinkSync(t),e()}catch(t){e(t)}},e.prototype.rmdir=function(t,e){try{this.rmdirSync(t),e()}catch(t){e(t)}},e.prototype.mkdir=function(t,e,n){try{this.mkdirSync(t,e),n()}catch(t){n(t)}},e.prototype.readdir=function(t,e){try{e(null,this.readdirSync(t))}catch(t){e(t)}},e.prototype.chmod=function(t,e,n,r){try{this.chmodSync(t,e,n),r()}catch(t){r(t)}},e.prototype.chown=function(t,e,n,r,i){try{this.chownSync(t,e,n,r),i()}catch(t){i(t)}},e.prototype.utimes=function(t,e,n,r){try{this.utimesSync(t,e,n),r()}catch(t){r(t)}},e.prototype.link=function(t,e,n){try{this.linkSync(t,e),n()}catch(t){n(t)}},e.prototype.symlink=function(t,e,n,r){try{this.symlinkSync(t,e,n),r()}catch(t){r(t)}},e.prototype.readlink=function(t,e){try{e(null,this.readlinkSync(t))}catch(t){e(t)}},e}(We),Ze=function(){};Ze.prototype.sync=function(t){t(new Fe(be.ENOTSUP))},Ze.prototype.syncSync=function(){throw new Fe(be.ENOTSUP)},Ze.prototype.datasync=function(t){this.sync(t)},Ze.prototype.datasyncSync=function(){return this.syncSync()},Ze.prototype.chown=function(t,e,n){n(new Fe(be.ENOTSUP))},Ze.prototype.chownSync=function(t,e){throw new Fe(be.ENOTSUP)},Ze.prototype.chmod=function(t,e){e(new Fe(be.ENOTSUP))},Ze.prototype.chmodSync=function(t){throw new Fe(be.ENOTSUP)},Ze.prototype.utimes=function(t,e,n){n(new Fe(be.ENOTSUP))},Ze.prototype.utimesSync=function(t,e){throw new Fe(be.ENOTSUP)};var Ye=function(e){function n(t,n,r,i,o){if(e.call(this),this._pos=0,this._dirty=!1,this._fs=t,this._path=n,this._flag=r,this._stat=i,o?this._buffer=o:this._buffer=S(),this._stat.size!==this._buffer.length&&this._flag.isReadable())throw new Error("Invalid buffer: Buffer is "+this._buffer.length+" long, yet Stats object specifies that file is "+this._stat.size+" long.")}return e&&(n.__proto__=e),n.prototype=Object.create(e&&e.prototype),n.prototype.constructor=n,n.prototype.getBuffer=function(){return this._buffer},n.prototype.getStats=function(){return this._stat},n.prototype.getFlag=function(){return this._flag},n.prototype.getPath=function(){return this._path},n.prototype.getPos=function(){return this._flag.isAppendable()?this._stat.size:this._pos},n.prototype.advancePos=function(t){return this._pos+=t},n.prototype.setPos=function(t){return this._pos=t},n.prototype.sync=function(t){try{this.syncSync(),t()}catch(e){t(e)}},n.prototype.syncSync=function(){throw new Fe(be.ENOTSUP)},n.prototype.close=function(t){try{this.closeSync(),t()}catch(e){t(e)}},n.prototype.closeSync=function(){throw new Fe(be.ENOTSUP)},n.prototype.stat=function(t){try{t(null,this._stat.clone())}catch(e){t(e)}},n.prototype.statSync=function(){return this._stat.clone()},n.prototype.truncate=function(t,e){try{this.truncateSync(t),this._flag.isSynchronous()&&!Pe.getRootFS().supportsSynch()&&this.sync(e),e()}catch(t){return e(t)}},n.prototype.truncateSync=function(e){if(this._dirty=!0,!this._flag.isWriteable())throw new Fe(be.EPERM,"File not opened with a writeable mode.");if(this._stat.mtime=new Date,e>this._buffer.length){var n=t.alloc(e-this._buffer.length,0);return this.writeSync(n,0,n.length,this._buffer.length),void(this._flag.isSynchronous()&&Pe.getRootFS().supportsSynch()&&this.syncSync())}this._stat.size=e;var r=t.alloc(e);this._buffer.copy(r,0,0,e),this._buffer=r,this._flag.isSynchronous()&&Pe.ge