pax_global_header00006660000000000000000000000064132510473510014513gustar00rootroot0000000000000052 comment=bac901d63eee226effb9149bf9511aac8d5853f0 offset-buffer-1.1.2/000077500000000000000000000000001325104735100142515ustar00rootroot00000000000000offset-buffer-1.1.2/.gitignore000066400000000000000000000000341325104735100162360ustar00rootroot00000000000000node_modules/ npm-debug.log offset-buffer-1.1.2/LICENSE000066400000000000000000000020361325104735100152570ustar00rootroot00000000000000Copyright 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.offset-buffer-1.1.2/README.md000066400000000000000000000005671325104735100155400ustar00rootroot00000000000000# 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. offset-buffer-1.1.2/index.js000066400000000000000000000211661325104735100157240ustar00rootroot00000000000000var 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()); }; offset-buffer-1.1.2/package-lock.json000066400000000000000000000105611325104735100174700ustar00rootroot00000000000000{ "name": "obuf", "version": "1.1.2", "lockfileVersion": 1, "requires": true, "dependencies": { "commander": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/commander/-/commander-2.3.0.tgz", "integrity": "sha1-/UMOiJgy7DU7ms0d4hfBHLPu+HM=", "dev": true }, "debug": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/debug/-/debug-2.0.0.tgz", "integrity": "sha1-ib2d9nMrUSVrxnBTQrugLtEhMe8=", "dev": true, "requires": { "ms": "0.6.2" } }, "diff": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/diff/-/diff-1.0.8.tgz", "integrity": "sha1-NDJ2MI7Jkbe8giZ+1VvBQR+XFmY=", "dev": true }, "escape-string-regexp": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz", "integrity": "sha1-Tbwv5nTnGUnK8/smlc5/LcHZqNE=", "dev": true }, "glob": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-3.2.3.tgz", "integrity": "sha1-4xPusknHr/qlxHUoaw4RW1mDlGc=", "dev": true, "requires": { "graceful-fs": "2.0.3", "inherits": "2.0.3", "minimatch": "0.2.14" } }, "graceful-fs": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-2.0.3.tgz", "integrity": "sha1-fNLNsiiko/Nule+mzBQt59GhNtA=", "dev": true }, "growl": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/growl/-/growl-1.8.1.tgz", "integrity": "sha1-Sy3sjZB+k9szZiTc7AGDUC+MlCg=", "dev": true }, "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", "dev": true }, "jade": { "version": "0.26.3", "resolved": "https://registry.npmjs.org/jade/-/jade-0.26.3.tgz", "integrity": "sha1-jxDXl32NefL2/4YqgbBRPMslaGw=", "dev": true, "requires": { "commander": "0.6.1", "mkdirp": "0.3.0" }, "dependencies": { "commander": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/commander/-/commander-0.6.1.tgz", "integrity": "sha1-+mihT2qUXVTbvlDYzbMyDp47GgY=", "dev": true }, "mkdirp": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz", "integrity": "sha1-G79asbqCevI1dRQ0kEJkVfSB/h4=", "dev": true } } }, "lru-cache": { "version": "2.7.3", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz", "integrity": "sha1-bUUk6LlV+V1PW1iFHOId1y+06VI=", "dev": true }, "minimatch": { "version": "0.2.14", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.2.14.tgz", "integrity": "sha1-x054BXT2PG+aCQ6Q775u9TpqdWo=", "dev": true, "requires": { "lru-cache": "2.7.3", "sigmund": "1.0.1" } }, "minimist": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", "dev": true }, "mkdirp": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.0.tgz", "integrity": "sha1-HXMHam35hs2TROFecfzAWkyavxI=", "dev": true, "requires": { "minimist": "0.0.8" } }, "mocha": { "version": "1.21.5", "resolved": "https://registry.npmjs.org/mocha/-/mocha-1.21.5.tgz", "integrity": "sha1-fFiwkXTfl25DSiOx6NY5hz/FKek=", "dev": true, "requires": { "commander": "2.3.0", "debug": "2.0.0", "diff": "1.0.8", "escape-string-regexp": "1.0.2", "glob": "3.2.3", "growl": "1.8.1", "jade": "0.26.3", "mkdirp": "0.5.0" } }, "ms": { "version": "0.6.2", "resolved": "https://registry.npmjs.org/ms/-/ms-0.6.2.tgz", "integrity": "sha1-2JwhJMb9wTU9Zai3e/GqxLGTcIw=", "dev": true }, "sigmund": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=", "dev": true } } } offset-buffer-1.1.2/package.json000066400000000000000000000010521325104735100165350ustar00rootroot00000000000000{ "name": "obuf", "version": "1.1.2", "description": "", "main": "index.js", "scripts": { "test": "mocha test/**/*-test.js" }, "repository": { "type": "git", "url": "git@github.com:indutny/offset-buffer" }, "keywords": [ "Offset", "Buffer", "reader" ], "author": "Fedor Indutny ", "license": "MIT", "bugs": { "url": "https://github.com/indutny/offset-buffer/issues" }, "homepage": "https://github.com/indutny/offset-buffer", "devDependencies": { "mocha": "^1.21.4" } } offset-buffer-1.1.2/test/000077500000000000000000000000001325104735100152305ustar00rootroot00000000000000offset-buffer-1.1.2/test/buffer-test.js000066400000000000000000000202041325104735100200120ustar00rootroot00000000000000var 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)); }); }); });