9 lines
242 KiB
JavaScript
9 lines
242 KiB
JavaScript
|
!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){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,n),i.loaded=!0,i.exports}return n.m=t,n.c=e,n.p="",n(0)}([function(t,e,n){(function(t,r,i,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var s,a=n(2),c=n(9);!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"}(s||(s={}));var u={};u[s.EPERM]="Operation not permitted.",u[s.ENOENT]="No such file or directory.",u[s.EIO]="Input/output error.",u[s.EBADF]="Bad file descriptor.",u[s.EACCES]="Permission denied.",u[s.EBUSY]="Resource busy or locked.",u[s.EEXIST]="File exists.",u[s.ENOTDIR]="File is not a directory.",u[s.EISDIR]="File is a directory.",u[s.EINVAL]="Invalid argument.",u[s.EFBIG]="File is too big.",u[s.ENOSPC]="No space left on disk.",u[s.EROFS]="Cannot modify a read-only file system.",u[s.ENOTEMPTY]="Directory is not empty.",u[s.ENOTSUP]="Operation is not supported.";var f,h=function(e){function n(t,n,r){void 0===n&&(n=u[t]),e.call(this,n),this.syscall="",this.errno=t,this.code=s[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,u[t],e)},n.ENOENT=function(t){return this.FileError(s.ENOENT,t)},n.EEXIST=function(t){return this.FileError(s.EEXIST,t)},n.EISDIR=function(t){return this.FileError(s.EISDIR,t)},n.ENOTDIR=function(t){return this.FileError(s.ENOTDIR,t)},n.EPERM=function(t){return this.FileError(s.EPERM,t)},n.ENOTEMPTY=function(t){return this.FileError(s.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),p=Object.freeze({get ErrorCode(){return s},ErrorStrings:u,ApiError:h});!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"}(f||(f={}));var l,d=function t(e){if(this.flagStr=e,t.validFlagStrs.indexOf(e)<0)throw new h(s.EINVAL,"Invalid flag: "+e)};d.getFileFlag=function(t){return d.flagCache.hasOwnProperty(t)?d.flagCache[t]:d.flagCache[t]=new d(t)},d.prototype.getFlagString=function(){return this.flagStr},d.prototype.isReadable=function(){return-1!==this.flagStr.indexOf("r")||-1!==this.flagStr.indexOf("+")},d.prototype.isWriteable=function(){return-1!==this.flagStr.indexOf("w")||-1!==this.flagStr.indexOf("a")||-1!==this.flagStr.indexOf("+")},d.prototype.isTruncating=function(){return-1!==this.flagStr.indexOf("w")},d.prototype.isAppendable=function(){return-1!==this.flagStr.indexOf("a")},d.prototype.isSynchronous=function(){return-1!==this.flagStr.indexOf("s")},d.prototype.isExclusive=function(){return-1!==this.flagStr.indexOf("x")},d.prototype.pathExistsAction=function(){return this.isExclusive()?f.THROW_EXCEPTION:this.isTruncating()?f.TRUNCATE_FILE:f.NOP},d.prototype.pathNotExistsAction=functio
|
||
|
/*!
|
||
|
* The buffer module from node.js, for the browser.
|
||
|
*
|
||
|
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
|
||
|
* @license MIT
|
||
|
*/
|
||
|
"use strict";var r=n(3),i=n(4);e.Buffer=t,e.SlowBuffer=function(e){+e!=e&&(e=0);return t.alloc(+e)},e.INSPECT_MAX_BYTES=50;var o=2147483647;function s(e){if(e>o)throw new RangeError("Invalid typed array length");var n=new Uint8Array(e);return n.__proto__=t.prototype,n}function t(t,e,n){if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return u(t)}return a(t,e,n)}function a(e,n,r){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return j(e)?function(e,n,r){if(n<0||e.byteLength<n)throw new RangeError("'offset' is out of bounds");if(e.byteLength<n+(r||0))throw new RangeError("'length' is out of bounds");var i;i=void 0===n&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,n):new Uint8Array(e,n,r);return i.__proto__=t.prototype,i}(e,n,r):"string"==typeof e?function(e,n){"string"==typeof n&&""!==n||(n="utf8");if(!t.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|p(e,n),i=s(r),o=i.write(e,n);o!==r&&(i=i.slice(0,o));return i}(e,n):function(e){if(t.isBuffer(e)){var n=0|h(e.length),r=s(n);return 0===r.length?r:(e.copy(r,0,0,n),r)}if(e){if(B(e)||"length"in e)return"number"!=typeof e.length||z(e.length)?s(0):f(e);if("Buffer"===e.type&&Array.isArray(e.data))return f(e.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e)}function c(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function u(t){return c(t),s(t<0?0:0|h(t))}function f(t){for(var e=t.length<0?0:0|h(t.length),n=s(e),r=0;r<e;r+=1)n[r]=255&t[r];return n}function h(t){if(t>=o)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o.toString(16)+" bytes");return 0|t}function p(e,n){if(t.isBuffer(e))return e.length;if(B(e)||j(e))return e.byteLength;"string"!=typeof e&&(e=""+e);var r=e.length;if(0===r)return 0;for(var i=!1;;)switch(n){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return C(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return U(e).length;default:if(i)return C(e).length;n=(""+n).toLowerCase(),i=!0}}function l(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function d(e,n,r,i,o){if(0===e.length)return-1;if("string"==typeof r?(i=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),z(r=+r)&&(r=o?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(o)return-1;r=e.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof n&&(n=t.from(n,i)),t.isBuffer(n))return 0===n.length?-1:y(e,n,r,i,o);if("number"==typeof n)return n&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,n,r):Uint8Array.prototype.lastIndexOf.call(e,n,r):y(e,[n],r,i,o);throw new TypeError("val must be string, number or Buffer")}function y(t,e,n,r,i){var o,s=1,a=t.length,c=e.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;s=2,a/=2,c/=2,n/=2}function u(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(i){var f=-1;for(o=n;o<a;o++)if(u(t,o)===u(e,-1===f?0:o-f)){if(-1===f&&(f=o),o-f+1===c)return f*s}else-1!==f&&(o-=o-f),f=-1}else for(n+c>a&&(n=a-c),o=n;o>=0;o--){for(var h=!0,p=0;p<c;p++)if(u(t,o+p)!==u(e,p)){h=!1;break}if(h)return o}return-1}function g(t,e,n,r){n=Number(n)||0;var i=t.length-n;r?(r=Number(r))>i&&(r=i):r=i;var o=e.length;if(o%2!=0)throw new TypeError("Invalid hex string");r>o/2&&(r=o/2);for(var s=0;s<r;++s){var a=parseInt(e.substr(2*s,2),16);if(z(a))return s;t[n+s]=a}return s}function m(t,e,n,r){return M(C(e,t.length-n),t,n,r)}function _(t,e,n,r){return M(function(t){for(var e=[],n=0;n<t.length;++n)e.push(255&t.charCodeAt(n));return e}(e),t,n,r)}function w(t,e,n,r){return _(t,e,n,r)}function v(t,e,n,r){return M(U(e),t,n,r)}function E(t,e,n,r){return M(function(t,e){for(var n,r,i,o=[],s=0;s<t.length&&!((e-=2)<0);++s)n=t.charCodeAt(s
|