Skip to content

Commit 95849ea

Browse files
committed
Use Long.js >=2.3
1 parent d5ecf34 commit 95849ea

15 files changed

+154
-264
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
npm-debug.log
3+
.idea/
34
ByteBuffer.png

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bytebuffer",
3-
"version": "4.0.0",
3+
"version": "4.1.0",
44
"author": "Daniel Wirtz <[email protected]>",
55
"description": "A full-featured ByteBuffer implementation using typed arrays.",
66
"main": "dist/ByteBufferAB.js",

dist/ByteBufferAB.js

Lines changed: 32 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
* @const
125125
* @expose
126126
*/
127-
ByteBuffer.VERSION = "4.0.0";
127+
ByteBuffer.VERSION = "4.1.0";
128128

129129
/**
130130
* Little endian constant that can be used instead of its boolean value. Evaluates to `true`.
@@ -2371,7 +2371,6 @@
23712371
ByteBufferPrototype.capacity = function() {
23722372
return this.buffer.byteLength;
23732373
};
2374-
23752374
/**
23762375
* Clears this ByteBuffer's offsets by setting {@link ByteBuffer#offset} to `0` and {@link ByteBuffer#limit} to the
23772376
* backing buffer's capacity. Discards {@link ByteBuffer#markedOffset}.
@@ -3052,23 +3051,17 @@
30523051
* @param {number=} begin Offset to begin at, defaults to {@link ByteBuffer#offset}.
30533052
* @param {number=} end Offset to end at, defaults to {@link ByteBuffer#limit}.
30543053
* @returns {string} Base64 encoded string
3054+
* @throws {RangeError} If `begin` or `end` is out of bounds
30553055
* @expose
30563056
*/
30573057
ByteBufferPrototype.toBase64 = function(begin, end) {
30583058
if (typeof begin === 'undefined')
30593059
begin = this.offset;
30603060
if (typeof end === 'undefined')
30613061
end = this.limit;
3062-
if (!this.noAssert) {
3063-
if (typeof begin !== 'number' || begin % 1 !== 0)
3064-
throw TypeError("Illegal begin: Not an integer");
3065-
begin >>>= 0;
3066-
if (typeof end !== 'number' || end % 1 !== 0)
3067-
throw TypeError("Illegal end: Not an integer");
3068-
end >>>= 0;
3069-
if (begin < 0 || begin > end || end > this.buffer.byteLength)
3070-
throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength);
3071-
}
3062+
begin = begin | 0; end = end | 0;
3063+
if (begin < 0 || end > this.capacity || begin > end)
3064+
throw RangeError("begin, end");
30723065
var sd; lxiv.encode(function() {
30733066
return begin < end ? this.view[begin++] : null;
30743067
}.bind(this), sd = stringDestination());
@@ -3080,19 +3073,13 @@
30803073
* @param {string} str String to decode
30813074
* @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to
30823075
* {@link ByteBuffer.DEFAULT_ENDIAN}.
3083-
* @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to
3084-
* {@link ByteBuffer.DEFAULT_NOASSERT}.
30853076
* @returns {!ByteBuffer} ByteBuffer
30863077
* @expose
30873078
*/
3088-
ByteBuffer.fromBase64 = function(str, littleEndian, noAssert) {
3089-
if (!noAssert) {
3090-
if (typeof str !== 'string')
3091-
throw TypeError("Illegal str: Not a string");
3092-
if (str.length % 4 !== 0)
3093-
throw TypeError("Illegal str: Length not a multiple of 4");
3094-
}
3095-
var bb = new ByteBuffer(str.length/4*3, littleEndian, noAssert),
3079+
ByteBuffer.fromBase64 = function(str, littleEndian) {
3080+
if (typeof str !== 'string')
3081+
throw TypeError("str");
3082+
var bb = new ByteBuffer(str.length/4*3, littleEndian),
30963083
i = 0;
30973084
lxiv.decode(stringSource(str), function(b) {
30983085
bb.view[i++] = b;
@@ -3134,51 +3121,45 @@
31343121
* @expose
31353122
*/
31363123
ByteBufferPrototype.toBinary = function(begin, end) {
3137-
begin = typeof begin === 'undefined' ? this.offset : begin;
3138-
end = typeof end === 'undefined' ? this.limit : end;
3139-
if (!this.noAssert) {
3140-
if (typeof begin !== 'number' || begin % 1 !== 0)
3141-
throw TypeError("Illegal begin: Not an integer");
3142-
begin >>>= 0;
3143-
if (typeof end !== 'number' || end % 1 !== 0)
3144-
throw TypeError("Illegal end: Not an integer");
3145-
end >>>= 0;
3146-
if (begin < 0 || begin > end || end > this.buffer.byteLength)
3147-
throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength);
3148-
}
3124+
if (typeof begin === 'undefined')
3125+
begin = this.offset;
3126+
if (typeof end === 'undefined')
3127+
end = this.limit;
3128+
begin |= 0; end |= 0;
3129+
if (begin < 0 || end > this.capacity() || begin > end)
3130+
throw RangeError("begin, end");
31493131
if (begin === end)
31503132
return "";
3151-
var cc = [], pt = [];
3133+
var chars = [],
3134+
parts = [];
31523135
while (begin < end) {
3153-
cc.push(this.view[begin++]);
3154-
if (cc.length >= 1024)
3155-
pt.push(String.fromCharCode.apply(String, cc)),
3156-
cc = [];
3136+
chars.push(this.view[begin++]);
3137+
if (chars.length >= 1024)
3138+
parts.push(String.fromCharCode.apply(String, chars)),
3139+
chars = [];
31573140
}
3158-
return pt.join('') + String.fromCharCode.apply(String, cc);
3141+
return parts.join('') + String.fromCharCode.apply(String, chars);
31593142
};
31603143

31613144
/**
31623145
* Decodes a binary encoded string, that is using only characters 0x00-0xFF as bytes, to a ByteBuffer.
31633146
* @param {string} str String to decode
31643147
* @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to
31653148
* {@link ByteBuffer.DEFAULT_ENDIAN}.
3166-
* @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to
3167-
* {@link ByteBuffer.DEFAULT_NOASSERT}.
31683149
* @returns {!ByteBuffer} ByteBuffer
31693150
* @expose
31703151
*/
3171-
ByteBuffer.fromBinary = function(str, littleEndian, noAssert) {
3172-
if (!noAssert) {
3173-
if (typeof str !== 'string')
3174-
throw TypeError("Illegal str: Not a string");
3175-
}
3176-
var i = 0, k = str.length, charCode,
3177-
bb = new ByteBuffer(k, littleEndian, noAssert);
3152+
ByteBuffer.fromBinary = function(str, littleEndian) {
3153+
if (typeof str !== 'string')
3154+
throw TypeError("str");
3155+
var i = 0,
3156+
k = str.length,
3157+
charCode,
3158+
bb = new ByteBuffer(k, littleEndian);
31783159
while (i<k) {
31793160
charCode = str.charCodeAt(i);
3180-
if (!noAssert && charCode > 255)
3181-
throw RangeError("Illegal charCode at "+i+": 0 <= "+charCode+" <= 255");
3161+
if (charCode > 0xff)
3162+
throw RangeError("illegal char code: "+charCode);
31823163
bb.view[i++] = charCode;
31833164
}
31843165
bb.limit = k;

0 commit comments

Comments
 (0)