diff --git a/.travis.yml b/.travis.yml index 58be165..0ba0ea9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,6 @@ node_js: - '4' - '6' - '8' - - '9' + - '10' script: "npm run test-travis" after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls" diff --git a/lib/byte.js b/lib/byte.js index 1b3de36..f384b6b 100644 --- a/lib/byte.js +++ b/lib/byte.js @@ -21,7 +21,7 @@ function ByteBuffer(options) { if (array) { this._bytes = array; } else { - this._bytes = new Buffer(this._size); + this._bytes = Buffer.alloc(this._size); } } @@ -57,12 +57,7 @@ ByteBuffer.prototype._checkSize = function (afterSize) { this._size = afterSize * 2; this._limit = this._size; debug('allocate new Buffer: from %d to %d bytes', old, this._size); - var bytes; - if (Buffer.allocUnsafe) { - bytes = Buffer.allocUnsafe(this._size); - } else { - bytes = new Buffer(this._size); - } + var bytes = Buffer.alloc(this._size); this._bytes.copy(bytes, 0); this._bytes = bytes; }; @@ -400,7 +395,7 @@ ByteBuffer.prototype._copy = function (start, end) { // if (end - start > 2048) { // return this._bytes.slice(start, end); // } - var buf = new Buffer(end - start); + var buf = Buffer.alloc(end - start); this._bytes.copy(buf, 0, start, end); return buf; }; @@ -594,7 +589,7 @@ ByteBuffer.prototype.flip = function () { ByteBuffer.prototype.clear = function () { this._limit = this._size; this._offset = 0; - this._bytes = new Buffer(this._size); + this._bytes = Buffer.alloc(this._size); return this; } diff --git a/test/byte.test.js b/test/byte.test.js index 3ab52e7..ef994ed 100644 --- a/test/byte.test.js +++ b/test/byte.test.js @@ -757,7 +757,7 @@ describe('byte.test.js', function () { var buf2 = new Buffer(1); assert.throws(function() { bytes.get(buf2); - }, 'BufferOverflowException'); + }, null, 'BufferOverflowException'); }); it('should get(dst, offset, length) again', function () { @@ -793,7 +793,7 @@ describe('byte.test.js', function () { bytes.put(0xfd); assert.throws(function () { bytes.getRawStringByStringLength(0, str.length + 1); - }, 'string is not valid UTF-8 encode'); + }, null, 'string is not valid UTF-8 encode'); }); });