xy-server/node_modules/byte-buffer/dist/byte-buffer.min.js

11 lines
8.7 KiB
JavaScript
Raw Normal View History

2025-04-23 09:34:08 +08:00
/**
* byte-buffer v2.0.0
* Copyright (c) 2012-2020 Tim Kurvers <tim@moonsphere.net>
* @license MIT
*
* Wrapper for JavaScript's ArrayBuffer/DataView.
*
* https://github.com/timkurvers/byte-buffer
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).ByteBuffer=e()}(this,(function(){"use strict";function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}var n=function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(t&&void 0!==t.byteLength)return void 0!==t.buffer?e?t.buffer.slice(0):t.buffer:e?t.slice(0):t;if(t&&void 0!==t.length){if(t.constructor===String)return null;try{return new Uint8Array(t).buffer}catch(t){return null}}return null},i=function(){function i(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.constructor.BIG_ENDIAN,o=arguments.length>2&&void 0!==arguments[2]&&arguments[2];t(this,i),this._buffer=null,this._raw=null,this._view=null,this._order=!!r,this._implicitGrowth=!!o,this._index=0;var a=n(e,!0);a||(a=new ArrayBuffer(e)),this.buffer=a}var r,o,a;return r=i,(o=[{key:"_sanitizeIndex",value:function(){this._index<0&&(this._index=0),this._index>this.length&&(this._index=this.length)}},{key:"front",value:function(){return this._index=0,this}},{key:"end",value:function(){return this._index=this.length,this}},{key:"seek",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.index+=t,this}},{key:"read",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.available;if(t>this.available)throw new Error("Cannot read ".concat(t," byte(s), ").concat(this.available," available"));if(t<=0)throw new RangeError("Invalid number of bytes ".concat(t));var e=new i(this._buffer.slice(this._index,this._index+t),this.order);return this._index+=t,e}},{key:"write",value:function(t){var e;if(t instanceof Uint8Array)e=t;else{var i=n(t);if(!i)throw new TypeError("Cannot write ".concat(t,", not a sequence"));e=new Uint8Array(i)}var r=this.available;if(e.byteLength>r){if(!this._implicitGrowth)throw new Error("Cannot write ".concat(t," using ").concat(e.byteLength," byte(s), ").concat(this.available," available"));this.append(e.byteLength-r)}return this._raw.set(e,this._index),this._index+=e.byteLength,this}},{key:"readString",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.available;if(t>this.available)throw new Error("Cannot read ".concat(t," byte(s), ").concat(this.available," available"));if(t<=0)throw new RangeError("Invalid number of bytes ".concat(t));for(var e=this._raw,n=[],i=0,r=null,o=null,a=null,h=null,s=this._index+t;this._index<s;)if((r=e[this._index])<128)n[i++]=r,this._index++;else{if(r<194)throw new Error("Unexpected continuation byte");if(r<224){if((o=e[this._index+1])<128||o>191)throw new Error("Bad continuation byte");n[i++]=((31&r)<<6)+(63&o),this._index+=2}else if(r<240){if((o=e[this._index+1])<128||o>191)throw new Error("Bad continuation byte");if((a=e[this._index+2])<128||a>191)throw new Error("Bad continuation byte");n[i++]=((15&r)<<12)+((63&o)<<6)+(63&a),this._index+=3}else{if(!(r<245))throw new Error("Illegal byte");if((o=e[this._index+1])<128||o>191)throw new Error("Bad continuation byte");if((a=e[this._index+2])<128||a>191)throw new Error("Bad continuation byte");if((h=e[this._index+3])<128||h>191)throw new Error("Bad continuation byte");var l=((7&r)<<18)+((63&o)<<12)+((63&a)<<6)+(63&h);l-=65536,n[i++]=55296+((1047552&l)>>>10),n[i++]=56320+(1023&l),this._index+=4}}var u=65536,f=n.length;if(f<u)return String.fromCharCode.apply(String,n);for(var c=[],d=0;d<f;)c.push(String.fromCharCode.apply(String,n.slice(d,d+u))),d+=u;return c.join("")}},{key:"writeString",value:function(t){for(var e=[],n=t.length,i=0,r=0;i<n;){var o=t.charCodeAt(i);if(o<=127)e[r++]=o;else if(o<=2047)e[r++]=192|(1984&o)>>>6,e[r++]=128|63&o;else if(o<=55295||o>=57344&&o<=65535)e[r++]=224|(61440&o)>>>12,e[r++]=128|(4032&o)>>>6,e[r++]=128|63&o;else{