diff --git a/lib/Data.js b/lib/Data.js index 42be026..401dfd0 100644 --- a/lib/Data.js +++ b/lib/Data.js @@ -11,7 +11,7 @@ function Data(capacity) { * @member {Buffer} * @private */ - this._buffer = new Buffer(capacity || 128) + this._buffer = Buffer.alloc(capacity || 128) /** * Number of used bytes @@ -91,7 +91,7 @@ Data.prototype._alloc = function (bytes) { buffLen *= 2 } while (this._length + bytes > buffLen) - newBuffer = new Buffer(buffLen) + newBuffer = Buffer.alloc(buffLen) this._buffer.copy(newBuffer, 0, 0, this._length) this._buffer = newBuffer } diff --git a/lib/types.js b/lib/types.js index 055635b..f422aae 100644 --- a/lib/types.js +++ b/lib/types.js @@ -129,7 +129,7 @@ module.exports.string = { throw new TypeError('Expected a string at ' + path + ', got ' + s) } - exports.Buffer.write(new Buffer(s), data, path) + exports.Buffer.write(Buffer.from(s), data, path) }, read: function (state) { return exports.Buffer.read(state).toString() @@ -189,7 +189,7 @@ module.exports.json = { */ module.exports.oid = { write: function (o, data, path) { - var buffer = new Buffer(String(o), 'hex') + var buffer = Buffer.from(String(o), 'hex') if (buffer.length !== 12) { throw new TypeError('Expected an object id (12 bytes) at ' + path + ', got ' + o) } diff --git a/test/types.js b/test/types.js index cdfc26b..faefd81 100644 --- a/test/types.js +++ b/test/types.js @@ -45,8 +45,8 @@ describe('types', function () { }) it('should be sound for Buffer', function () { - check(types.Buffer, new Buffer([])) - check(types.Buffer, new Buffer([3, 14, 15, 92, 65, 35])) + check(types.Buffer, Buffer.from([])) + check(types.Buffer, Buffer.from([3, 14, 15, 92, 65, 35])) }) it('should be sound for boolean', function () { @@ -99,7 +99,7 @@ function write(type, value) { * @return {*} */ function read(hexStr, type) { - var state = new ReadState(new Buffer(hexStr, 'hex')), + var state = new ReadState(Buffer.from(hexStr, 'hex')), r = type.read(state) state.hasEnded().should.be.true() return r