first
This commit is contained in:
20
node_modules/obuf/LICENSE
generated
vendored
Normal file
20
node_modules/obuf/LICENSE
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
Copyright Fedor Indutny, 2015.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
persons to whom the Software is furnished to do so, subject to the
|
||||
following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
12
node_modules/obuf/README.md
generated
vendored
Normal file
12
node_modules/obuf/README.md
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
# obuf - Offset buffer implementation.
|
||||
|
||||
Byte buffer specialized for data in chunks with special cases for dropping
|
||||
bytes in the front, merging bytes in to various integer types and
|
||||
abandoning buffer without penalty for previous chunk merges.
|
||||
|
||||
Used in spyd-transport, part of spdy support for http2.
|
||||
|
||||
This software is licensed under the MIT License.
|
||||
|
||||
By Fedor Indutny, 2015.
|
||||
|
396
node_modules/obuf/index.js
generated
vendored
Normal file
396
node_modules/obuf/index.js
generated
vendored
Normal file
@ -0,0 +1,396 @@
|
||||
var Buffer = require('buffer').Buffer;
|
||||
|
||||
function OffsetBuffer() {
|
||||
this.offset = 0;
|
||||
this.size = 0;
|
||||
this.buffers = [];
|
||||
}
|
||||
module.exports = OffsetBuffer;
|
||||
|
||||
OffsetBuffer.prototype.isEmpty = function isEmpty() {
|
||||
return this.size === 0;
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.clone = function clone(size) {
|
||||
var r = new OffsetBuffer();
|
||||
r.offset = this.offset;
|
||||
r.size = size;
|
||||
r.buffers = this.buffers.slice();
|
||||
return r;
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.toChunks = function toChunks() {
|
||||
if (this.size === 0)
|
||||
return [];
|
||||
|
||||
// We are going to slice it anyway
|
||||
if (this.offset !== 0) {
|
||||
this.buffers[0] = this.buffers[0].slice(this.offset);
|
||||
this.offset = 0;
|
||||
}
|
||||
|
||||
var chunks = [ ];
|
||||
var off = 0;
|
||||
for (var i = 0; off <= this.size && i < this.buffers.length; i++) {
|
||||
var buf = this.buffers[i];
|
||||
off += buf.length;
|
||||
|
||||
// Slice off last buffer
|
||||
if (off > this.size) {
|
||||
buf = buf.slice(0, buf.length - (off - this.size));
|
||||
this.buffers[i] = buf;
|
||||
}
|
||||
|
||||
chunks.push(buf);
|
||||
}
|
||||
|
||||
// If some buffers were skipped - trim length
|
||||
if (i < this.buffers.length)
|
||||
this.buffers.length = i;
|
||||
|
||||
return chunks;
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.toString = function toString(enc) {
|
||||
return this.toChunks().map(function(c) {
|
||||
return c.toString(enc);
|
||||
}).join('');
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.use = function use(buf, off, n) {
|
||||
this.buffers = [ buf ];
|
||||
this.offset = off;
|
||||
this.size = n;
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.push = function push(data) {
|
||||
// Ignore empty writes
|
||||
if (data.length === 0)
|
||||
return;
|
||||
|
||||
this.size += data.length;
|
||||
this.buffers.push(data);
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.has = function has(n) {
|
||||
return this.size >= n;
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.skip = function skip(n) {
|
||||
if (this.size === 0)
|
||||
return;
|
||||
|
||||
this.size -= n;
|
||||
|
||||
// Fast case, skip bytes in a first buffer
|
||||
if (this.offset + n < this.buffers[0].length) {
|
||||
this.offset += n;
|
||||
return;
|
||||
}
|
||||
|
||||
var left = n - (this.buffers[0].length - this.offset);
|
||||
this.offset = 0;
|
||||
|
||||
for (var shift = 1; left > 0 && shift < this.buffers.length; shift++) {
|
||||
var buf = this.buffers[shift];
|
||||
if (buf.length > left) {
|
||||
this.offset = left;
|
||||
break;
|
||||
}
|
||||
left -= buf.length;
|
||||
}
|
||||
this.buffers = this.buffers.slice(shift);
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.copy = function copy(target, targetOff, off, n) {
|
||||
if (this.size === 0)
|
||||
return;
|
||||
if (off !== 0)
|
||||
throw new Error('Unsupported offset in .copy()');
|
||||
|
||||
var toff = targetOff;
|
||||
var first = this.buffers[0];
|
||||
var toCopy = Math.min(n, first.length - this.offset);
|
||||
first.copy(target, toff, this.offset, this.offset + toCopy);
|
||||
|
||||
toff += toCopy;
|
||||
var left = n - toCopy;
|
||||
for (var i = 1; left > 0 && i < this.buffers.length; i++) {
|
||||
var buf = this.buffers[i];
|
||||
var toCopy = Math.min(left, buf.length);
|
||||
|
||||
buf.copy(target, toff, 0, toCopy);
|
||||
|
||||
toff += toCopy;
|
||||
left -= toCopy;
|
||||
}
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.take = function take(n) {
|
||||
if (n === 0)
|
||||
return new Buffer(0);
|
||||
|
||||
this.size -= n;
|
||||
|
||||
// Fast cases
|
||||
var first = this.buffers[0].length - this.offset;
|
||||
if (first === n) {
|
||||
var r = this.buffers.shift();
|
||||
if (this.offset !== 0) {
|
||||
r = r.slice(this.offset);
|
||||
this.offset = 0;
|
||||
}
|
||||
return r;
|
||||
} else if (first > n) {
|
||||
var r = this.buffers[0].slice(this.offset, this.offset + n);
|
||||
this.offset += n;
|
||||
return r;
|
||||
}
|
||||
|
||||
// Allocate and fill buffer
|
||||
var out = new Buffer(n);
|
||||
var toOff = 0;
|
||||
var startOff = this.offset;
|
||||
for (var i = 0; toOff !== n && i < this.buffers.length; i++) {
|
||||
var buf = this.buffers[i];
|
||||
var toCopy = Math.min(buf.length - startOff, n - toOff);
|
||||
|
||||
buf.copy(out, toOff, startOff, startOff + toCopy);
|
||||
if (startOff + toCopy < buf.length) {
|
||||
this.offset = startOff + toCopy;
|
||||
break;
|
||||
} else {
|
||||
toOff += toCopy;
|
||||
startOff = 0;
|
||||
}
|
||||
}
|
||||
|
||||
this.buffers = this.buffers.slice(i);
|
||||
if (this.buffers.length === 0)
|
||||
this.offset = 0;
|
||||
|
||||
return out;
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.peekUInt8 = function peekUInt8() {
|
||||
return this.buffers[0][this.offset];
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.readUInt8 = function readUInt8() {
|
||||
this.size -= 1;
|
||||
var first = this.buffers[0];
|
||||
var r = first[this.offset];
|
||||
if (++this.offset === first.length) {
|
||||
this.offset = 0;
|
||||
this.buffers.shift();
|
||||
}
|
||||
|
||||
return r;
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.readUInt16LE = function readUInt16LE() {
|
||||
var first = this.buffers[0];
|
||||
this.size -= 2;
|
||||
|
||||
var r;
|
||||
var shift;
|
||||
|
||||
// Fast case - first buffer has all bytes
|
||||
if (first.length - this.offset >= 2) {
|
||||
r = first.readUInt16LE(this.offset);
|
||||
shift = 0;
|
||||
this.offset += 2;
|
||||
|
||||
// One byte here - one byte there
|
||||
} else {
|
||||
r = first[this.offset] | (this.buffers[1][0] << 8);
|
||||
shift = 1;
|
||||
this.offset = 1;
|
||||
}
|
||||
|
||||
if (this.offset === this.buffers[shift].length) {
|
||||
this.offset = 0;
|
||||
shift++;
|
||||
}
|
||||
if (shift !== 0)
|
||||
this.buffers = this.buffers.slice(shift);
|
||||
|
||||
return r;
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.readUInt24LE = function readUInt24LE() {
|
||||
var first = this.buffers[0];
|
||||
|
||||
var r;
|
||||
var shift;
|
||||
var firstHas = first.length - this.offset;
|
||||
|
||||
// Fast case - first buffer has all bytes
|
||||
if (firstHas >= 3) {
|
||||
r = first.readUInt16LE(this.offset) | (first[this.offset + 2] << 16);
|
||||
shift = 0;
|
||||
this.offset += 3;
|
||||
|
||||
// First buffer has 2 of 3 bytes
|
||||
} else if (firstHas >= 2) {
|
||||
r = first.readUInt16LE(this.offset) | (this.buffers[1][0] << 16);
|
||||
shift = 1;
|
||||
this.offset = 1;
|
||||
|
||||
// Slow case: First buffer has 1 of 3 bytes
|
||||
} else {
|
||||
r = first[this.offset];
|
||||
this.offset = 0;
|
||||
this.buffers.shift();
|
||||
this.size -= 1;
|
||||
|
||||
r |= this.readUInt16LE() << 8;
|
||||
return r;
|
||||
}
|
||||
|
||||
this.size -= 3;
|
||||
if (this.offset === this.buffers[shift].length) {
|
||||
this.offset = 0;
|
||||
shift++;
|
||||
}
|
||||
if (shift !== 0)
|
||||
this.buffers = this.buffers.slice(shift);
|
||||
|
||||
return r;
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.readUInt32LE = function readUInt32LE() {
|
||||
var first = this.buffers[0];
|
||||
|
||||
var r;
|
||||
var shift;
|
||||
var firstHas = first.length - this.offset;
|
||||
|
||||
// Fast case - first buffer has all bytes
|
||||
if (firstHas >= 4) {
|
||||
r = first.readUInt32LE(this.offset);
|
||||
shift = 0;
|
||||
this.offset += 4;
|
||||
|
||||
// First buffer has 3 of 4 bytes
|
||||
} else if (firstHas >= 3) {
|
||||
r = (first.readUInt16LE(this.offset) |
|
||||
(first[this.offset + 2] << 16)) +
|
||||
(this.buffers[1][0] * 0x1000000);
|
||||
shift = 1;
|
||||
this.offset = 1;
|
||||
|
||||
// Slow case: First buffer has 2 of 4 bytes
|
||||
} else if (firstHas >= 2) {
|
||||
r = first.readUInt16LE(this.offset);
|
||||
this.offset = 0;
|
||||
this.buffers.shift();
|
||||
this.size -= 2;
|
||||
|
||||
r += this.readUInt16LE() * 0x10000;
|
||||
return r;
|
||||
|
||||
// Slow case: First buffer has 1 of 4 bytes
|
||||
} else {
|
||||
r = first[this.offset];
|
||||
this.offset = 0;
|
||||
this.buffers.shift();
|
||||
this.size -= 1;
|
||||
|
||||
r += this.readUInt24LE() * 0x100;
|
||||
return r;
|
||||
}
|
||||
|
||||
this.size -= 4;
|
||||
if (this.offset === this.buffers[shift].length) {
|
||||
this.offset = 0;
|
||||
shift++;
|
||||
}
|
||||
if (shift !== 0)
|
||||
this.buffers = this.buffers.slice(shift);
|
||||
|
||||
return r;
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.readUInt16BE = function readUInt16BE() {
|
||||
var r = this.readUInt16LE();
|
||||
|
||||
return ((r & 0xff) << 8) | (r >> 8);
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.readUInt24BE = function readUInt24BE() {
|
||||
var r = this.readUInt24LE();
|
||||
|
||||
return ((r & 0xff) << 16) | (((r >> 8) & 0xff) << 8) | (r >> 16);
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.readUInt32BE = function readUInt32BE() {
|
||||
var r = this.readUInt32LE();
|
||||
|
||||
return (((r & 0xff) << 24) |
|
||||
(((r >>> 8) & 0xff) << 16) |
|
||||
(((r >>> 16) & 0xff) << 8) |
|
||||
(r >>> 24)) >>> 0;
|
||||
};
|
||||
|
||||
// Signed number APIs
|
||||
|
||||
function signedInt8(num) {
|
||||
if (num >= 0x80)
|
||||
return -(0xff ^ num) - 1;
|
||||
else
|
||||
return num;
|
||||
}
|
||||
|
||||
OffsetBuffer.prototype.peekInt8 = function peekInt8() {
|
||||
return signedInt8(this.peekUInt8());
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.readInt8 = function readInt8() {
|
||||
return signedInt8(this.readUInt8());
|
||||
};
|
||||
|
||||
function signedInt16(num) {
|
||||
if (num >= 0x8000)
|
||||
return -(0xffff ^ num) - 1;
|
||||
else
|
||||
return num;
|
||||
}
|
||||
|
||||
OffsetBuffer.prototype.readInt16BE = function readInt16BE() {
|
||||
return signedInt16(this.readUInt16BE());
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.readInt16LE = function readInt16LE() {
|
||||
return signedInt16(this.readUInt16LE());
|
||||
};
|
||||
|
||||
function signedInt24(num) {
|
||||
if (num >= 0x800000)
|
||||
return -(0xffffff ^ num) - 1;
|
||||
else
|
||||
return num;
|
||||
}
|
||||
|
||||
OffsetBuffer.prototype.readInt24BE = function readInt24BE() {
|
||||
return signedInt24(this.readUInt24BE());
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.readInt24LE = function readInt24LE() {
|
||||
return signedInt24(this.readUInt24LE());
|
||||
};
|
||||
|
||||
function signedInt32(num) {
|
||||
if (num >= 0x80000000)
|
||||
return -(0xffffffff ^ num) - 1;
|
||||
else
|
||||
return num;
|
||||
}
|
||||
|
||||
OffsetBuffer.prototype.readInt32BE = function readInt32BE() {
|
||||
return signedInt32(this.readUInt32BE());
|
||||
};
|
||||
|
||||
OffsetBuffer.prototype.readInt32LE = function readInt32LE() {
|
||||
return signedInt32(this.readUInt32LE());
|
||||
};
|
56
node_modules/obuf/package.json
generated
vendored
Normal file
56
node_modules/obuf/package.json
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
{
|
||||
"_from": "obuf@^1.1.2",
|
||||
"_id": "obuf@1.1.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-PX1wu0AmAdPqOL1mWhqmlOd8kOIZQwGZw6rh7uby9fTc5lhaOWFLX3I6R1hrF9k3zUY40e6igsLGkDXK92LJNg==",
|
||||
"_location": "/obuf",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "obuf@^1.1.2",
|
||||
"name": "obuf",
|
||||
"escapedName": "obuf",
|
||||
"rawSpec": "^1.1.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.1.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/hpack.js",
|
||||
"/spdy-transport"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/obuf/-/obuf-1.1.2.tgz",
|
||||
"_shasum": "09bea3343d41859ebd446292d11c9d4db619084e",
|
||||
"_spec": "obuf@^1.1.2",
|
||||
"_where": "C:\\Users\\zhouxueli\\Desktop\\scheduling-app\\node_modules\\spdy-transport",
|
||||
"author": {
|
||||
"name": "Fedor Indutny",
|
||||
"email": "fedor@indutny.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/indutny/offset-buffer/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Byte buffer specialized for data in chunks with special cases for dropping bytes in the front, merging bytes in to various integer types and abandoning buffer without penalty for previous chunk merges.",
|
||||
"devDependencies": {
|
||||
"mocha": "^1.21.4"
|
||||
},
|
||||
"homepage": "https://github.com/indutny/offset-buffer",
|
||||
"keywords": [
|
||||
"Offset",
|
||||
"Buffer",
|
||||
"reader"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "obuf",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/indutny/offset-buffer.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha test/**/*-test.js"
|
||||
},
|
||||
"version": "1.1.2"
|
||||
}
|
268
node_modules/obuf/test/buffer-test.js
generated
vendored
Normal file
268
node_modules/obuf/test/buffer-test.js
generated
vendored
Normal file
@ -0,0 +1,268 @@
|
||||
var assert = require('assert');
|
||||
var OffsetBuffer = require('../');
|
||||
|
||||
describe('OffsetBuffer', function() {
|
||||
var o;
|
||||
beforeEach(function() {
|
||||
o = new OffsetBuffer();
|
||||
});
|
||||
|
||||
describe('.take()', function() {
|
||||
it('should return empty buffer', function() {
|
||||
var b = new Buffer('hello world');
|
||||
o.push(b);
|
||||
var r = o.take(0);
|
||||
assert.equal(r.length, 0);
|
||||
assert.equal(o.size, b.length);
|
||||
});
|
||||
|
||||
it('should return the first buffer itself', function() {
|
||||
var b = new Buffer('hello world');
|
||||
o.push(b);
|
||||
var r = o.take(b.length);
|
||||
assert(r === b);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
|
||||
it('should return the slice of the buffer ', function() {
|
||||
var b = new Buffer('hello world');
|
||||
o.push(b);
|
||||
assert.equal(o.take(5).toString(), 'hello');
|
||||
assert.equal(o.take(1).toString(), ' ');
|
||||
assert.equal(o.take(5).toString(), 'world');
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
|
||||
it('should concat buffers', function() {
|
||||
o.push(new Buffer('hello'));
|
||||
o.push(new Buffer(' '));
|
||||
o.push(new Buffer('world!'));
|
||||
assert.equal(o.take(11).toString(), 'hello world');
|
||||
assert.equal(o.take(1).toString(), '!');
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('.skip', function() {
|
||||
it('should skip bytes', function() {
|
||||
o.push(new Buffer('hello '));
|
||||
o.push(new Buffer('world'));
|
||||
o.push(new Buffer(' oh gosh'));
|
||||
|
||||
assert.equal(o.take(2).toString(), 'he');
|
||||
o.skip(1);
|
||||
assert.equal(o.take(2).toString(), 'lo');
|
||||
o.skip(1);
|
||||
assert.equal(o.take(2).toString(), 'wo');
|
||||
o.skip(4);
|
||||
assert.equal(o.take(7).toString(), 'oh gosh');
|
||||
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('.peekUInt8', function() {
|
||||
it('should return and not move by one byte', function() {
|
||||
o.push(new Buffer([ 0x1, 0x2 ]));
|
||||
assert.equal(o.peekUInt8(), 1);
|
||||
assert.equal(o.readUInt8(), 1);
|
||||
assert.equal(o.peekUInt8(), 2);
|
||||
assert.equal(o.readUInt8(), 2);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('.peekInt8', function() {
|
||||
it('should return signed number', function() {
|
||||
o.push(new Buffer([ 0x80 ]));
|
||||
assert.equal(o.peekInt8(), -128);
|
||||
assert.equal(o.readInt8(), -128);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('.readUInt8', function() {
|
||||
it('should return and move by one byte', function() {
|
||||
o.push(new Buffer([ 0x1, 0x2 ]));
|
||||
o.push(new Buffer([ 0x3, 0x4 ]));
|
||||
assert.equal(o.readUInt8(), 1);
|
||||
assert.equal(o.readUInt8(), 2);
|
||||
assert.equal(o.readUInt8(), 3);
|
||||
assert.equal(o.readUInt8(), 4);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('.readInt8', function() {
|
||||
it('should return signed number', function() {
|
||||
o.push(new Buffer([ 0x8f, 0x7f ]));
|
||||
assert.equal(o.readInt8(), -113);
|
||||
assert.equal(o.readInt8(), 127);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('.readUInt16LE', function() {
|
||||
it('should return and move by two bytes', function() {
|
||||
o.push(new Buffer([ 0x1, 0x2, 0x3 ]));
|
||||
o.push(new Buffer([ 0x4, 0x5, 0x6 ]));
|
||||
assert.equal(o.readUInt16LE(), 0x0201);
|
||||
assert.equal(o.readUInt16LE(), 0x0403);
|
||||
assert.equal(o.readUInt16LE(), 0x0605);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
|
||||
it('should return and move by two bytes (regression #1)', function() {
|
||||
o.push(new Buffer([ 0x1 ]));
|
||||
o.push(new Buffer([ 0x2, 0x3, 0x4 ]));
|
||||
assert.equal(o.readUInt16LE(), 0x0201);
|
||||
assert.equal(o.readUInt16LE(), 0x0403);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('.readInt16LE', function() {
|
||||
it('should return signed number', function() {
|
||||
o.push(new Buffer([ 0x23, 0x81 ]));
|
||||
assert.equal(o.readInt16LE(), -32477);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('.readUInt24LE', function() {
|
||||
it('should return and move by three bytes', function() {
|
||||
o.push(new Buffer([ 0x1, 0x2, 0x3, 0x4, 0x5 ]));
|
||||
o.push(new Buffer([ 0x6, 0x7 ]));
|
||||
o.push(new Buffer([ 0x8, 0x9 ]));
|
||||
assert.equal(o.readUInt24LE(), 0x030201);
|
||||
assert.equal(o.readUInt24LE(), 0x060504);
|
||||
assert.equal(o.readUInt24LE(), 0x090807);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
|
||||
it('should return and move by three bytes (regression #1)', function() {
|
||||
o.push(new Buffer([ 0x1, 0x2 ]));
|
||||
o.push(new Buffer([ 0x3 ]));
|
||||
assert.equal(o.readUInt24LE(), 0x030201);
|
||||
assert.equal(o.buffers.length, 0);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('.readInt24LE', function() {
|
||||
it('should return signed number', function() {
|
||||
o.push(new Buffer([ 0x23, 0x45, 0x81 ]));
|
||||
assert.equal(o.readInt24LE(), -8305373);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('.readUInt32LE', function() {
|
||||
it('should return and move by four bytes', function() {
|
||||
o.push(new Buffer([ 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7 ]));
|
||||
o.push(new Buffer([ 0x8, 0x9, 0xa ]));
|
||||
o.push(new Buffer([ 0xb, 0xc, 0xd ]));
|
||||
o.push(new Buffer([ 0xe, 0xf, 0x10 ]));
|
||||
assert.equal(o.readUInt32LE(), 0x04030201);
|
||||
assert.equal(o.readUInt32LE(), 0x08070605);
|
||||
assert.equal(o.readUInt32LE(), 0x0c0b0a09);
|
||||
assert.equal(o.readUInt32LE(), 0x100f0e0d);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
|
||||
it('should return and move by four bytes (regression #1)', function() {
|
||||
o.push(new Buffer([ 0x1, 0x2, 0x3 ]));
|
||||
o.push(new Buffer([ 0x4 ]));
|
||||
assert.equal(o.readUInt32LE(), 0x04030201);
|
||||
assert.equal(o.buffers.length, 0);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('.readInt32LE', function() {
|
||||
it('should return signed number', function() {
|
||||
o.push(new Buffer([ 0xff, 0xff, 0xff, 0xff ]));
|
||||
assert.equal(o.readInt32LE(), -1);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('.readUInt16BE', function() {
|
||||
it('should return and move by two bytes', function() {
|
||||
o.push(new Buffer([ 0x1, 0x2, 0x3 ]));
|
||||
o.push(new Buffer([ 0x4, 0x5, 0x6 ]));
|
||||
assert.equal(o.readUInt16BE(), 0x0102);
|
||||
assert.equal(o.readUInt16BE(), 0x0304);
|
||||
assert.equal(o.readUInt16BE(), 0x0506);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('.readInt16BE', function() {
|
||||
it('should return signed number', function() {
|
||||
o.push(new Buffer([ 0x81, 0x23 ]));
|
||||
assert.equal(o.readInt16BE(), -32477);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('.readUInt24BE', function() {
|
||||
it('should return and move by three bytes', function() {
|
||||
o.push(new Buffer([ 0x1, 0x2, 0x3, 0x4, 0x5 ]));
|
||||
o.push(new Buffer([ 0x6, 0x7 ]));
|
||||
o.push(new Buffer([ 0x8, 0x9 ]));
|
||||
assert.equal(o.readUInt24BE(), 0x010203);
|
||||
assert.equal(o.readUInt24BE(), 0x040506);
|
||||
assert.equal(o.readUInt24BE(), 0x070809);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('.readInt24BE', function() {
|
||||
it('should return signed number', function() {
|
||||
o.push(new Buffer([ 0x81, 0x45, 0x23 ]));
|
||||
assert.equal(o.readInt24BE(), -8305373);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('.readUInt32BE', function() {
|
||||
it('should return and move by four bytes', function() {
|
||||
o.push(new Buffer([ 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7 ]));
|
||||
o.push(new Buffer([ 0x8, 0x9, 0xa ]));
|
||||
o.push(new Buffer([ 0xb, 0xc, 0xd ]));
|
||||
o.push(new Buffer([ 0xe, 0xf, 0x10 ]));
|
||||
assert.equal(o.readUInt32BE(), 0x01020304);
|
||||
assert.equal(o.readUInt32BE(), 0x05060708);
|
||||
assert.equal(o.readUInt32BE(), 0x090a0b0c);
|
||||
assert.equal(o.readUInt32BE(), 0x0d0e0f10);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
|
||||
it('should return positive values', function() {
|
||||
o.push(new Buffer([ 0xff, 0xff, 0xff, 0xff ]));
|
||||
assert.equal(o.readUInt32BE(), 0xffffffff);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('.readInt32BE', function() {
|
||||
it('should return signed number', function() {
|
||||
o.push(new Buffer([ 0xff, 0xff, 0xff, 0xff ]));
|
||||
assert.equal(o.readInt32BE(), -1);
|
||||
assert(o.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('.has', function() {
|
||||
it('should properly check the amount of the remaining bytes', function() {
|
||||
o.push(new Buffer([ 1, 2, 3 ]));
|
||||
assert(o.has(3));
|
||||
assert.equal(o.readUInt8(), 0x01);
|
||||
assert(!o.has(3));
|
||||
assert(o.has(2));
|
||||
assert.equal(o.readUInt16BE(), 0x0203);
|
||||
assert(!o.has(1));
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user