New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

peerjs-js-binarypack

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

peerjs-js-binarypack - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

.idea/codeStyles/codeStyleConfig.xml

35

dist/binarypack.js

@@ -195,15 +195,28 @@ /*! binarypack.js build:1.0.1, production. Copyright(c) 2012 Eric Zhang <eric@ericzhang.com> MIT Licensed */(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){

c = bytes[i];
if (c < 128) {
str += String.fromCharCode(c);
// The length of a UTF-8 sequence is specified in the first byte:
// 0xxxxxxx means length 1,
// 110xxxxx means length 2,
// 1110xxxx means length 3,
// 11110xxx means length 4.
// 10xxxxxx is for non-initial bytes.
if (c < 0xa0) {
// One-byte sequence: bits 0xxxxxxx
code = c;
i++;
} else if ((c ^ 0xc0) < 32) {
code = ((c ^ 0xc0) << 6) | (bytes[i + 1] & 63);
str += String.fromCharCode(code);
} else if ((c ^ 0xc0) < 0x20) {
// Two-byte sequence: bits 110xxxxx 10xxxxxx
code = ((c & 0x1f) << 6) | (bytes[i + 1] & 0x3f);
i += 2;
} else if ((c ^ 0xe0) < 0x10) {
// Three-byte sequence: bits 1110xxxx 10xxxxxx 10xxxxxx
code = ((c & 0x0f) << 12) | (bytes[i + 1] & 0x3f) << 6 |
(bytes[i + 2] & 0x3f);
i += 3;
} else {
code = ((c & 15) << 12) | ((bytes[i + 1] & 63) << 6) |
(bytes[i + 2] & 63);
str += String.fromCharCode(code);
i += 3;
// Four-byte sequence: bits 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
code = ((c & 0x07) << 18) | (bytes[i + 1] & 0x3f) << 12 |
(bytes[i + 2] & 0x3f) << 6 | (bytes[i + 3] & 0x3f);
i += 4;
}
str += String.fromCodePoint(code);
}

@@ -508,3 +521,3 @@

function _utf8Replace (m) {
var code = m.charCodeAt(0);
var code = m.codePointAt(0);

@@ -523,3 +536,3 @@ if (code <= 0x7ff) return '00';

} else {
return str.replace(/[^\u0000-\u007F]/g, _utf8Replace).length;
return str.replace(/[\ud800-\udbff][\udc00-\udfff]|[^\u0000-\u007f]/g, _utf8Replace).length;
}

@@ -526,0 +539,0 @@ }

@@ -1,1 +0,1 @@

/*! binarypack.js build:1.0.1, production. Copyright(c) 2012 Eric Zhang <eric@ericzhang.com> MIT Licensed */!function u(a,p,f){function s(t,e){if(!p[t]){if(!a[t]){var r="function"==typeof require&&require;if(!e&&r)return r(t,!0);if(o)return o(t,!0);var i=new Error("Cannot find module '"+t+"'");throw i.code="MODULE_NOT_FOUND",i}var n=p[t]={exports:{}};a[t][0].call(n.exports,function(e){return s(a[t][1][e]||e)},n,n.exports,u,a,p,f)}return p[t].exports}for(var o="function"==typeof require&&require,e=0;e<f.length;e++)s(f[e]);return s}({1:[function(e,t,r){var i=e("./bufferbuilder").BufferBuilder,n=e("./bufferbuilder").binaryFeatures,u={unpack:function(e){return new a(e).unpack()},pack:function(e){var t=new p;return t.pack(e),t.getBuffer()}};function a(e){this.index=0,this.dataBuffer=e,this.dataView=new Uint8Array(this.dataBuffer),this.length=this.dataBuffer.byteLength}function p(){this.bufferBuilder=new i}function f(e){var t=e.charCodeAt(0);return t<=2047?"00":t<=65535?"000":t<=2097151?"0000":t<=67108863?"00000":"000000"}t.exports=u,a.prototype.unpack=function(){var e,t=this.unpack_uint8();if(t<128)return t;if((224^t)<32)return(224^t)-32;if((e=160^t)<=15)return this.unpack_raw(e);if((e=176^t)<=15)return this.unpack_string(e);if((e=144^t)<=15)return this.unpack_array(e);if((e=128^t)<=15)return this.unpack_map(e);switch(t){case 192:return null;case 193:return;case 194:return!1;case 195:return!0;case 202:return this.unpack_float();case 203:return this.unpack_double();case 204:return this.unpack_uint8();case 205:return this.unpack_uint16();case 206:return this.unpack_uint32();case 207:return this.unpack_uint64();case 208:return this.unpack_int8();case 209:return this.unpack_int16();case 210:return this.unpack_int32();case 211:return this.unpack_int64();case 212:case 213:case 214:case 215:return;case 216:return e=this.unpack_uint16(),this.unpack_string(e);case 217:return e=this.unpack_uint32(),this.unpack_string(e);case 218:return e=this.unpack_uint16(),this.unpack_raw(e);case 219:return e=this.unpack_uint32(),this.unpack_raw(e);case 220:return e=this.unpack_uint16(),this.unpack_array(e);case 221:return e=this.unpack_uint32(),this.unpack_array(e);case 222:return e=this.unpack_uint16(),this.unpack_map(e);case 223:return e=this.unpack_uint32(),this.unpack_map(e)}},a.prototype.unpack_uint8=function(){var e=255&this.dataView[this.index];return this.index++,e},a.prototype.unpack_uint16=function(){var e=this.read(2),t=256*(255&e[0])+(255&e[1]);return this.index+=2,t},a.prototype.unpack_uint32=function(){var e=this.read(4),t=256*(256*(256*e[0]+e[1])+e[2])+e[3];return this.index+=4,t},a.prototype.unpack_uint64=function(){var e=this.read(8),t=256*(256*(256*(256*(256*(256*(256*e[0]+e[1])+e[2])+e[3])+e[4])+e[5])+e[6])+e[7];return this.index+=8,t},a.prototype.unpack_int8=function(){var e=this.unpack_uint8();return e<128?e:e-256},a.prototype.unpack_int16=function(){var e=this.unpack_uint16();return e<32768?e:e-65536},a.prototype.unpack_int32=function(){var e=this.unpack_uint32();return e<Math.pow(2,31)?e:e-Math.pow(2,32)},a.prototype.unpack_int64=function(){var e=this.unpack_uint64();return e<Math.pow(2,63)?e:e-Math.pow(2,64)},a.prototype.unpack_raw=function(e){if(this.length<this.index+e)throw new Error("BinaryPackFailure: index is out of range "+this.index+" "+e+" "+this.length);var t=this.dataBuffer.slice(this.index,this.index+e);return this.index+=e,t},a.prototype.unpack_string=function(e){for(var t,r,i=this.read(e),n=0,u="";n<e;)(t=i[n])<128?(u+=String.fromCharCode(t),n++):(192^t)<32?(r=(192^t)<<6|63&i[n+1],u+=String.fromCharCode(r),n+=2):(r=(15&t)<<12|(63&i[n+1])<<6|63&i[n+2],u+=String.fromCharCode(r),n+=3);return this.index+=e,u},a.prototype.unpack_array=function(e){for(var t=new Array(e),r=0;r<e;r++)t[r]=this.unpack();return t},a.prototype.unpack_map=function(e){for(var t={},r=0;r<e;r++){var i=this.unpack(),n=this.unpack();t[i]=n}return t},a.prototype.unpack_float=function(){var e=this.unpack_uint32(),t=(e>>23&255)-127;return(0==e>>31?1:-1)*(8388607&e|8388608)*Math.pow(2,t-23)},a.prototype.unpack_double=function(){var e=this.unpack_uint32(),t=this.unpack_uint32(),r=(e>>20&2047)-1023;return(0==e>>31?1:-1)*((1048575&e|1048576)*Math.pow(2,r-20)+t*Math.pow(2,r-52))},a.prototype.read=function(e){var t=this.index;if(t+e<=this.length)return this.dataView.subarray(t,t+e);throw new Error("BinaryPackFailure: read index out of range")},p.prototype.getBuffer=function(){return this.bufferBuilder.getBuffer()},p.prototype.pack=function(e){var t=typeof e;if("string"==t)this.pack_string(e);else if("number"==t)Math.floor(e)===e?this.pack_integer(e):this.pack_double(e);else if("boolean"==t)!0===e?this.bufferBuilder.append(195):!1===e&&this.bufferBuilder.append(194);else if("undefined"==t)this.bufferBuilder.append(192);else{if("object"!=t)throw new Error('Type "'+t+'" not yet supported');if(null===e)this.bufferBuilder.append(192);else{var r=e.constructor;if(r==Array)this.pack_array(e);else if(r==Blob||r==File||e instanceof Blob||e instanceof File)this.pack_bin(e);else if(r==ArrayBuffer)n.useArrayBufferView?this.pack_bin(new Uint8Array(e)):this.pack_bin(e);else if("BYTES_PER_ELEMENT"in e)n.useArrayBufferView?this.pack_bin(new Uint8Array(e.buffer)):this.pack_bin(e.buffer);else if(r==Object||r.toString().startsWith("class"))this.pack_object(e);else if(r==Date)this.pack_string(e.toString());else{if("function"!=typeof e.toBinaryPack)throw new Error('Type "'+r.toString()+'" not yet supported');this.bufferBuilder.append(e.toBinaryPack())}}}this.bufferBuilder.flush()},p.prototype.pack_bin=function(e){var t=e.length||e.byteLength||e.size;if(t<=15)this.pack_uint8(160+t);else if(t<=65535)this.bufferBuilder.append(218),this.pack_uint16(t);else{if(!(t<=4294967295))throw new Error("Invalid length");this.bufferBuilder.append(219),this.pack_uint32(t)}this.bufferBuilder.append(e)},p.prototype.pack_string=function(e){var t=function(e){return 600<e.length?new Blob([e]).size:e.replace(/[^\u0000-\u007F]/g,f).length}(e);if(t<=15)this.pack_uint8(176+t);else if(t<=65535)this.bufferBuilder.append(216),this.pack_uint16(t);else{if(!(t<=4294967295))throw new Error("Invalid length");this.bufferBuilder.append(217),this.pack_uint32(t)}this.bufferBuilder.append(e)},p.prototype.pack_array=function(e){var t=e.length;if(t<=15)this.pack_uint8(144+t);else if(t<=65535)this.bufferBuilder.append(220),this.pack_uint16(t);else{if(!(t<=4294967295))throw new Error("Invalid length");this.bufferBuilder.append(221),this.pack_uint32(t)}for(var r=0;r<t;r++)this.pack(e[r])},p.prototype.pack_integer=function(e){if(-32<=e&&e<=127)this.bufferBuilder.append(255&e);else if(0<=e&&e<=255)this.bufferBuilder.append(204),this.pack_uint8(e);else if(-128<=e&&e<=127)this.bufferBuilder.append(208),this.pack_int8(e);else if(0<=e&&e<=65535)this.bufferBuilder.append(205),this.pack_uint16(e);else if(-32768<=e&&e<=32767)this.bufferBuilder.append(209),this.pack_int16(e);else if(0<=e&&e<=4294967295)this.bufferBuilder.append(206),this.pack_uint32(e);else if(-2147483648<=e&&e<=2147483647)this.bufferBuilder.append(210),this.pack_int32(e);else if(-0x8000000000000000<=e&&e<=0x8000000000000000)this.bufferBuilder.append(211),this.pack_int64(e);else{if(!(0<=e&&e<=0x10000000000000000))throw new Error("Invalid integer");this.bufferBuilder.append(207),this.pack_uint64(e)}},p.prototype.pack_double=function(e){var t=0;e<0&&(t=1,e=-e);var r=Math.floor(Math.log(e)/Math.LN2),i=e/Math.pow(2,r)-1,n=Math.floor(i*Math.pow(2,52)),u=Math.pow(2,32),a=t<<31|r+1023<<20|n/u&1048575,p=n%u;this.bufferBuilder.append(203),this.pack_int32(a),this.pack_int32(p)},p.prototype.pack_object=function(e){var t=Object.keys(e).length;if(t<=15)this.pack_uint8(128+t);else if(t<=65535)this.bufferBuilder.append(222),this.pack_uint16(t);else{if(!(t<=4294967295))throw new Error("Invalid length");this.bufferBuilder.append(223),this.pack_uint32(t)}for(var r in e)e.hasOwnProperty(r)&&(this.pack(r),this.pack(e[r]))},p.prototype.pack_uint8=function(e){this.bufferBuilder.append(e)},p.prototype.pack_uint16=function(e){this.bufferBuilder.append(e>>8),this.bufferBuilder.append(255&e)},p.prototype.pack_uint32=function(e){var t=4294967295&e;this.bufferBuilder.append((4278190080&t)>>>24),this.bufferBuilder.append((16711680&t)>>>16),this.bufferBuilder.append((65280&t)>>>8),this.bufferBuilder.append(255&t)},p.prototype.pack_uint64=function(e){var t=e/Math.pow(2,32),r=e%Math.pow(2,32);this.bufferBuilder.append((4278190080&t)>>>24),this.bufferBuilder.append((16711680&t)>>>16),this.bufferBuilder.append((65280&t)>>>8),this.bufferBuilder.append(255&t),this.bufferBuilder.append((4278190080&r)>>>24),this.bufferBuilder.append((16711680&r)>>>16),this.bufferBuilder.append((65280&r)>>>8),this.bufferBuilder.append(255&r)},p.prototype.pack_int8=function(e){this.bufferBuilder.append(255&e)},p.prototype.pack_int16=function(e){this.bufferBuilder.append((65280&e)>>8),this.bufferBuilder.append(255&e)},p.prototype.pack_int32=function(e){this.bufferBuilder.append(e>>>24&255),this.bufferBuilder.append((16711680&e)>>>16),this.bufferBuilder.append((65280&e)>>>8),this.bufferBuilder.append(255&e)},p.prototype.pack_int64=function(e){var t=Math.floor(e/Math.pow(2,32)),r=e%Math.pow(2,32);this.bufferBuilder.append((4278190080&t)>>>24),this.bufferBuilder.append((16711680&t)>>>16),this.bufferBuilder.append((65280&t)>>>8),this.bufferBuilder.append(255&t),this.bufferBuilder.append((4278190080&r)>>>24),this.bufferBuilder.append((16711680&r)>>>16),this.bufferBuilder.append((65280&r)>>>8),this.bufferBuilder.append(255&r)}},{"./bufferbuilder":2}],2:[function(e,t,r){var i={};i.useBlobBuilder=function(){try{return new Blob([]),!1}catch(e){return!0}}(),i.useArrayBufferView=!i.useBlobBuilder&&function(){try{return 0===new Blob([new Uint8Array([])]).size}catch(e){return!0}}(),t.exports.binaryFeatures=i;var n=t.exports.BlobBuilder;function u(){this._pieces=[],this._parts=[]}"undefined"!=typeof window&&(n=t.exports.BlobBuilder=window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder||window.BlobBuilder),u.prototype.append=function(e){"number"==typeof e?this._pieces.push(e):(this.flush(),this._parts.push(e))},u.prototype.flush=function(){if(0<this._pieces.length){var e=new Uint8Array(this._pieces);i.useArrayBufferView||(e=e.buffer),this._parts.push(e),this._pieces=[]}},u.prototype.getBuffer=function(){if(this.flush(),i.useBlobBuilder){for(var e=new n,t=0,r=this._parts.length;t<r;t++)e.append(this._parts[t]);return e.getBlob()}return new Blob(this._parts)},t.exports.BufferBuilder=u},{}],3:[function(e,t,r){var i=e("./bufferbuilder");window.BufferBuilder=i.BufferBuilder,window.binaryFeatures=i.binaryFeatures,window.BlobBuilder=i.BlobBuilder,window.BinaryPack=e("./binarypack")},{"./binarypack":1,"./bufferbuilder":2}]},{},[3]);
/*! binarypack.js build:1.0.1, production. Copyright(c) 2012 Eric Zhang <eric@ericzhang.com> MIT Licensed */!function u(a,p,f){function s(t,e){if(!p[t]){if(!a[t]){var r="function"==typeof require&&require;if(!e&&r)return r(t,!0);if(o)return o(t,!0);var i=new Error("Cannot find module '"+t+"'");throw i.code="MODULE_NOT_FOUND",i}var n=p[t]={exports:{}};a[t][0].call(n.exports,function(e){return s(a[t][1][e]||e)},n,n.exports,u,a,p,f)}return p[t].exports}for(var o="function"==typeof require&&require,e=0;e<f.length;e++)s(f[e]);return s}({1:[function(e,t,r){var i=e("./bufferbuilder").BufferBuilder,n=e("./bufferbuilder").binaryFeatures,u={unpack:function(e){return new a(e).unpack()},pack:function(e){var t=new p;return t.pack(e),t.getBuffer()}};function a(e){this.index=0,this.dataBuffer=e,this.dataView=new Uint8Array(this.dataBuffer),this.length=this.dataBuffer.byteLength}function p(){this.bufferBuilder=new i}function f(e){var t=e.codePointAt(0);return t<=2047?"00":t<=65535?"000":t<=2097151?"0000":t<=67108863?"00000":"000000"}t.exports=u,a.prototype.unpack=function(){var e,t=this.unpack_uint8();if(t<128)return t;if((224^t)<32)return(224^t)-32;if((e=160^t)<=15)return this.unpack_raw(e);if((e=176^t)<=15)return this.unpack_string(e);if((e=144^t)<=15)return this.unpack_array(e);if((e=128^t)<=15)return this.unpack_map(e);switch(t){case 192:return null;case 193:return;case 194:return!1;case 195:return!0;case 202:return this.unpack_float();case 203:return this.unpack_double();case 204:return this.unpack_uint8();case 205:return this.unpack_uint16();case 206:return this.unpack_uint32();case 207:return this.unpack_uint64();case 208:return this.unpack_int8();case 209:return this.unpack_int16();case 210:return this.unpack_int32();case 211:return this.unpack_int64();case 212:case 213:case 214:case 215:return;case 216:return e=this.unpack_uint16(),this.unpack_string(e);case 217:return e=this.unpack_uint32(),this.unpack_string(e);case 218:return e=this.unpack_uint16(),this.unpack_raw(e);case 219:return e=this.unpack_uint32(),this.unpack_raw(e);case 220:return e=this.unpack_uint16(),this.unpack_array(e);case 221:return e=this.unpack_uint32(),this.unpack_array(e);case 222:return e=this.unpack_uint16(),this.unpack_map(e);case 223:return e=this.unpack_uint32(),this.unpack_map(e)}},a.prototype.unpack_uint8=function(){var e=255&this.dataView[this.index];return this.index++,e},a.prototype.unpack_uint16=function(){var e=this.read(2),t=256*(255&e[0])+(255&e[1]);return this.index+=2,t},a.prototype.unpack_uint32=function(){var e=this.read(4),t=256*(256*(256*e[0]+e[1])+e[2])+e[3];return this.index+=4,t},a.prototype.unpack_uint64=function(){var e=this.read(8),t=256*(256*(256*(256*(256*(256*(256*e[0]+e[1])+e[2])+e[3])+e[4])+e[5])+e[6])+e[7];return this.index+=8,t},a.prototype.unpack_int8=function(){var e=this.unpack_uint8();return e<128?e:e-256},a.prototype.unpack_int16=function(){var e=this.unpack_uint16();return e<32768?e:e-65536},a.prototype.unpack_int32=function(){var e=this.unpack_uint32();return e<Math.pow(2,31)?e:e-Math.pow(2,32)},a.prototype.unpack_int64=function(){var e=this.unpack_uint64();return e<Math.pow(2,63)?e:e-Math.pow(2,64)},a.prototype.unpack_raw=function(e){if(this.length<this.index+e)throw new Error("BinaryPackFailure: index is out of range "+this.index+" "+e+" "+this.length);var t=this.dataBuffer.slice(this.index,this.index+e);return this.index+=e,t},a.prototype.unpack_string=function(e){for(var t,r,i=this.read(e),n=0,u="";n<e;)(t=i[n])<160?(r=t,n++):(192^t)<32?(r=(31&t)<<6|63&i[n+1],n+=2):(224^t)<16?(r=(15&t)<<12|(63&i[n+1])<<6|63&i[n+2],n+=3):(r=(7&t)<<18|(63&i[n+1])<<12|(63&i[n+2])<<6|63&i[n+3],n+=4),u+=String.fromCodePoint(r);return this.index+=e,u},a.prototype.unpack_array=function(e){for(var t=new Array(e),r=0;r<e;r++)t[r]=this.unpack();return t},a.prototype.unpack_map=function(e){for(var t={},r=0;r<e;r++){var i=this.unpack(),n=this.unpack();t[i]=n}return t},a.prototype.unpack_float=function(){var e=this.unpack_uint32(),t=(e>>23&255)-127;return(0==e>>31?1:-1)*(8388607&e|8388608)*Math.pow(2,t-23)},a.prototype.unpack_double=function(){var e=this.unpack_uint32(),t=this.unpack_uint32(),r=(e>>20&2047)-1023;return(0==e>>31?1:-1)*((1048575&e|1048576)*Math.pow(2,r-20)+t*Math.pow(2,r-52))},a.prototype.read=function(e){var t=this.index;if(t+e<=this.length)return this.dataView.subarray(t,t+e);throw new Error("BinaryPackFailure: read index out of range")},p.prototype.getBuffer=function(){return this.bufferBuilder.getBuffer()},p.prototype.pack=function(e){var t=typeof e;if("string"==t)this.pack_string(e);else if("number"==t)Math.floor(e)===e?this.pack_integer(e):this.pack_double(e);else if("boolean"==t)!0===e?this.bufferBuilder.append(195):!1===e&&this.bufferBuilder.append(194);else if("undefined"==t)this.bufferBuilder.append(192);else{if("object"!=t)throw new Error('Type "'+t+'" not yet supported');if(null===e)this.bufferBuilder.append(192);else{var r=e.constructor;if(r==Array)this.pack_array(e);else if(r==Blob||r==File||e instanceof Blob||e instanceof File)this.pack_bin(e);else if(r==ArrayBuffer)n.useArrayBufferView?this.pack_bin(new Uint8Array(e)):this.pack_bin(e);else if("BYTES_PER_ELEMENT"in e)n.useArrayBufferView?this.pack_bin(new Uint8Array(e.buffer)):this.pack_bin(e.buffer);else if(r==Object||r.toString().startsWith("class"))this.pack_object(e);else if(r==Date)this.pack_string(e.toString());else{if("function"!=typeof e.toBinaryPack)throw new Error('Type "'+r.toString()+'" not yet supported');this.bufferBuilder.append(e.toBinaryPack())}}}this.bufferBuilder.flush()},p.prototype.pack_bin=function(e){var t=e.length||e.byteLength||e.size;if(t<=15)this.pack_uint8(160+t);else if(t<=65535)this.bufferBuilder.append(218),this.pack_uint16(t);else{if(!(t<=4294967295))throw new Error("Invalid length");this.bufferBuilder.append(219),this.pack_uint32(t)}this.bufferBuilder.append(e)},p.prototype.pack_string=function(e){var t=function(e){return 600<e.length?new Blob([e]).size:e.replace(/[\ud800-\udbff][\udc00-\udfff]|[^\u0000-\u007f]/g,f).length}(e);if(t<=15)this.pack_uint8(176+t);else if(t<=65535)this.bufferBuilder.append(216),this.pack_uint16(t);else{if(!(t<=4294967295))throw new Error("Invalid length");this.bufferBuilder.append(217),this.pack_uint32(t)}this.bufferBuilder.append(e)},p.prototype.pack_array=function(e){var t=e.length;if(t<=15)this.pack_uint8(144+t);else if(t<=65535)this.bufferBuilder.append(220),this.pack_uint16(t);else{if(!(t<=4294967295))throw new Error("Invalid length");this.bufferBuilder.append(221),this.pack_uint32(t)}for(var r=0;r<t;r++)this.pack(e[r])},p.prototype.pack_integer=function(e){if(-32<=e&&e<=127)this.bufferBuilder.append(255&e);else if(0<=e&&e<=255)this.bufferBuilder.append(204),this.pack_uint8(e);else if(-128<=e&&e<=127)this.bufferBuilder.append(208),this.pack_int8(e);else if(0<=e&&e<=65535)this.bufferBuilder.append(205),this.pack_uint16(e);else if(-32768<=e&&e<=32767)this.bufferBuilder.append(209),this.pack_int16(e);else if(0<=e&&e<=4294967295)this.bufferBuilder.append(206),this.pack_uint32(e);else if(-2147483648<=e&&e<=2147483647)this.bufferBuilder.append(210),this.pack_int32(e);else if(-0x8000000000000000<=e&&e<=0x8000000000000000)this.bufferBuilder.append(211),this.pack_int64(e);else{if(!(0<=e&&e<=0x10000000000000000))throw new Error("Invalid integer");this.bufferBuilder.append(207),this.pack_uint64(e)}},p.prototype.pack_double=function(e){var t=0;e<0&&(t=1,e=-e);var r=Math.floor(Math.log(e)/Math.LN2),i=e/Math.pow(2,r)-1,n=Math.floor(i*Math.pow(2,52)),u=Math.pow(2,32),a=t<<31|r+1023<<20|n/u&1048575,p=n%u;this.bufferBuilder.append(203),this.pack_int32(a),this.pack_int32(p)},p.prototype.pack_object=function(e){var t=Object.keys(e).length;if(t<=15)this.pack_uint8(128+t);else if(t<=65535)this.bufferBuilder.append(222),this.pack_uint16(t);else{if(!(t<=4294967295))throw new Error("Invalid length");this.bufferBuilder.append(223),this.pack_uint32(t)}for(var r in e)e.hasOwnProperty(r)&&(this.pack(r),this.pack(e[r]))},p.prototype.pack_uint8=function(e){this.bufferBuilder.append(e)},p.prototype.pack_uint16=function(e){this.bufferBuilder.append(e>>8),this.bufferBuilder.append(255&e)},p.prototype.pack_uint32=function(e){var t=4294967295&e;this.bufferBuilder.append((4278190080&t)>>>24),this.bufferBuilder.append((16711680&t)>>>16),this.bufferBuilder.append((65280&t)>>>8),this.bufferBuilder.append(255&t)},p.prototype.pack_uint64=function(e){var t=e/Math.pow(2,32),r=e%Math.pow(2,32);this.bufferBuilder.append((4278190080&t)>>>24),this.bufferBuilder.append((16711680&t)>>>16),this.bufferBuilder.append((65280&t)>>>8),this.bufferBuilder.append(255&t),this.bufferBuilder.append((4278190080&r)>>>24),this.bufferBuilder.append((16711680&r)>>>16),this.bufferBuilder.append((65280&r)>>>8),this.bufferBuilder.append(255&r)},p.prototype.pack_int8=function(e){this.bufferBuilder.append(255&e)},p.prototype.pack_int16=function(e){this.bufferBuilder.append((65280&e)>>8),this.bufferBuilder.append(255&e)},p.prototype.pack_int32=function(e){this.bufferBuilder.append(e>>>24&255),this.bufferBuilder.append((16711680&e)>>>16),this.bufferBuilder.append((65280&e)>>>8),this.bufferBuilder.append(255&e)},p.prototype.pack_int64=function(e){var t=Math.floor(e/Math.pow(2,32)),r=e%Math.pow(2,32);this.bufferBuilder.append((4278190080&t)>>>24),this.bufferBuilder.append((16711680&t)>>>16),this.bufferBuilder.append((65280&t)>>>8),this.bufferBuilder.append(255&t),this.bufferBuilder.append((4278190080&r)>>>24),this.bufferBuilder.append((16711680&r)>>>16),this.bufferBuilder.append((65280&r)>>>8),this.bufferBuilder.append(255&r)}},{"./bufferbuilder":2}],2:[function(e,t,r){var i={};i.useBlobBuilder=function(){try{return new Blob([]),!1}catch(e){return!0}}(),i.useArrayBufferView=!i.useBlobBuilder&&function(){try{return 0===new Blob([new Uint8Array([])]).size}catch(e){return!0}}(),t.exports.binaryFeatures=i;var n=t.exports.BlobBuilder;function u(){this._pieces=[],this._parts=[]}"undefined"!=typeof window&&(n=t.exports.BlobBuilder=window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder||window.BlobBuilder),u.prototype.append=function(e){"number"==typeof e?this._pieces.push(e):(this.flush(),this._parts.push(e))},u.prototype.flush=function(){if(0<this._pieces.length){var e=new Uint8Array(this._pieces);i.useArrayBufferView||(e=e.buffer),this._parts.push(e),this._pieces=[]}},u.prototype.getBuffer=function(){if(this.flush(),i.useBlobBuilder){for(var e=new n,t=0,r=this._parts.length;t<r;t++)e.append(this._parts[t]);return e.getBlob()}return new Blob(this._parts)},t.exports.BufferBuilder=u},{}],3:[function(e,t,r){var i=e("./bufferbuilder");window.BufferBuilder=i.BufferBuilder,window.binaryFeatures=i.binaryFeatures,window.BlobBuilder=i.BlobBuilder,window.BinaryPack=e("./binarypack")},{"./binarypack":1,"./bufferbuilder":2}]},{},[3]);

@@ -194,15 +194,28 @@ var BufferBuilder = require('./bufferbuilder').BufferBuilder;

c = bytes[i];
if (c < 128) {
str += String.fromCharCode(c);
// The length of a UTF-8 sequence is specified in the first byte:
// 0xxxxxxx means length 1,
// 110xxxxx means length 2,
// 1110xxxx means length 3,
// 11110xxx means length 4.
// 10xxxxxx is for non-initial bytes.
if (c < 0xa0) {
// One-byte sequence: bits 0xxxxxxx
code = c;
i++;
} else if ((c ^ 0xc0) < 32) {
code = ((c ^ 0xc0) << 6) | (bytes[i + 1] & 63);
str += String.fromCharCode(code);
} else if ((c ^ 0xc0) < 0x20) {
// Two-byte sequence: bits 110xxxxx 10xxxxxx
code = ((c & 0x1f) << 6) | (bytes[i + 1] & 0x3f);
i += 2;
} else if ((c ^ 0xe0) < 0x10) {
// Three-byte sequence: bits 1110xxxx 10xxxxxx 10xxxxxx
code = ((c & 0x0f) << 12) | (bytes[i + 1] & 0x3f) << 6 |
(bytes[i + 2] & 0x3f);
i += 3;
} else {
code = ((c & 15) << 12) | ((bytes[i + 1] & 63) << 6) |
(bytes[i + 2] & 63);
str += String.fromCharCode(code);
i += 3;
// Four-byte sequence: bits 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
code = ((c & 0x07) << 18) | (bytes[i + 1] & 0x3f) << 12 |
(bytes[i + 2] & 0x3f) << 6 | (bytes[i + 3] & 0x3f);
i += 4;
}
str += String.fromCodePoint(code);
}

@@ -507,3 +520,3 @@

function _utf8Replace (m) {
var code = m.charCodeAt(0);
var code = m.codePointAt(0);

@@ -522,4 +535,4 @@ if (code <= 0x7ff) return '00';

} else {
return str.replace(/[^\u0000-\u007F]/g, _utf8Replace).length;
return str.replace(/[\ud800-\udbff][\udc00-\udfff]|[^\u0000-\u007f]/g, _utf8Replace).length;
}
}
{
"name": "peerjs-js-binarypack",
"version": "1.0.1",
"version": "1.0.2",
"description": "BinaryPack serialization for the web browser",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/peers/js-binarypack",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc