From 6e1d885d800714a74acce38932f3445312ea496d Mon Sep 17 00:00:00 2001 From: Alexander Penev Date: Mon, 11 Mar 2019 13:39:42 +0200 Subject: [PATCH 1/4] Update buffer --- examples/app7.js | 4 +- lib/protocol/Connection.js | 4 +- lib/protocol/Reader.js | 4 +- lib/protocol/Writer.js | 38 ++++++++--------- lib/protocol/auth/SAML.js | 2 +- lib/protocol/auth/SCRAMSHA256.js | 10 ++--- lib/protocol/auth/SessionCookie.js | 6 +-- lib/protocol/common/Constants.js | 2 +- lib/protocol/data/Fields.js | 4 +- lib/protocol/data/Int32.js | 2 +- lib/protocol/data/MultilineOptions.js | 2 +- lib/protocol/data/Options.js | 4 +- lib/protocol/data/ReadLobRequest.js | 4 +- lib/protocol/data/TextList.js | 2 +- lib/protocol/reply/Part.js | 10 ++--- lib/protocol/reply/Segment.js | 2 +- lib/protocol/request/Part.js | 2 +- lib/protocol/request/Segment.js | 2 +- lib/util/convert.js | 2 +- test/acceptance/db.Prepare.js | 2 +- test/auth.Manager.js | 22 +++++----- test/data.Binary.js | 4 +- test/data.Default.js | 4 +- test/data.Fields.js | 22 +++++----- test/data.Int32.js | 4 +- test/data.Options.js | 2 +- test/data.ParameterMetadata.js | 2 +- test/data.Parameters.js | 6 +-- test/data.ReadLob.js | 8 ++-- test/data.SqlError.js | 2 +- test/data.Text.js | 16 +++---- test/data.WriteLob.js | 2 +- test/fixtures/parametersData.js | 28 ++++++------- test/fixtures/resultSetData.js | 2 +- test/fixtures/resultSetMetadata.js | 2 +- test/fixtures/topogolyInformation.js | 2 +- test/lib.Connection.js | 10 ++--- test/lib.ExecuteTask.js | 12 +++--- test/lib.Lob.js | 26 ++++++------ test/lib.Reader.js | 50 +++++++++++----------- test/lib.Result.js | 10 ++--- test/lib.ResultSet.js | 28 ++++++------- test/lib.ResultSetTransform.js | 10 ++--- test/lib.Statement.js | 2 +- test/lib.Writer.js | 38 ++++++++--------- test/mock/MockSocket.js | 4 +- test/mock/data/dbConnectInfo.js | 4 +- test/mock/data/execute.js | 60 +++++++++++++-------------- test/mock/data/executeDirect.js | 28 ++++++------- test/mock/data/fetch.js | 2 +- test/mock/data/prepare.js | 30 +++++++------- test/mock/data/readLob.js | 2 +- test/mock/data/writeLob.js | 4 +- test/mock/server.js | 10 ++--- test/part.StatementContext.js | 2 +- test/rep.part.js | 6 +-- test/rep.segment.js | 14 +++---- test/req.Authenticate.js | 8 ++-- test/util.bignum.js | 20 ++++----- test/util.convert.js | 4 +- test/util.index.js | 2 +- 61 files changed, 311 insertions(+), 311 deletions(-) diff --git a/examples/app7.js b/examples/app7.js index 3d38919..f1e3c6a 100644 --- a/examples/app7.js +++ b/examples/app7.js @@ -68,13 +68,13 @@ function insert(statement, cb) { 1, 'SAP AG', fs.createReadStream(path.join(dirname, 'sap.jpg')), fs.createReadStream(path.join(dirname, 'logo.png')), - new Buffer('SAP headquarters located in Walldorf, Germany', 'ascii') + Buffer.from('SAP headquarters located in Walldorf, Germany', 'ascii') ], [ 2, 'SAP lobby', fs.createReadStream(path.join(dirname, 'lobby.jpg')), fs.createReadStream(path.join(dirname, 'locked.png')), - new Buffer('SAP lobby in Walldorf, Germany', 'ascii') + Buffer.from('SAP lobby in Walldorf, Germany', 'ascii') ] ]; diff --git a/lib/protocol/Connection.js b/lib/protocol/Connection.js index 6fd7211..98e86c4 100644 --- a/lib/protocol/Connection.js +++ b/lib/protocol/Connection.js @@ -275,7 +275,7 @@ Connection.prototype.send = function send(message, receive) { var size = MAX_PACKET_SIZE - PACKET_HEADER_LENGTH; var buffer = message.toBuffer(size); - var packet = new Buffer(PACKET_HEADER_LENGTH + buffer.length); + var packet = Buffer.allocUnsafe(PACKET_HEADER_LENGTH + buffer.length); buffer.copy(packet, PACKET_HEADER_LENGTH); var state = this._state; @@ -618,6 +618,6 @@ InitializationReply.read = function readInitializationReply(buffer) { return new InitializationReply(productVersion, protocolVersion); }; -var initializationRequestBuffer = new Buffer([ +var initializationRequestBuffer = Buffer.from([ 0xff, 0xff, 0xff, 0xff, 4, 20, 0, 4, 1, 0, 0, 1, 1, 1 ]); diff --git a/lib/protocol/Reader.js b/lib/protocol/Reader.js index 1dd165b..8b8b309 100644 --- a/lib/protocol/Reader.js +++ b/lib/protocol/Reader.js @@ -97,7 +97,7 @@ Reader.prototype.readBytes = function readBytes(isString) { this.buffer.slice(this.offset, this.offset + length), this.scrictEncoding); } else { - value = new Buffer(length); + value = Buffer.allocUnsafe(length); this.buffer.copy(value, 0, this.offset, this.offset + length); } this.offset += length; @@ -253,7 +253,7 @@ Reader.prototype.readLob = function readLob(defaultType) { chunk = this.buffer.slice(this.offset, this.offset + chunkLength); this.offset += chunkLength; } else { - chunk = new Buffer(0); + chunk = Buffer.allocUnsafe(0); } // if (!byteLength && !charLength) { return null; } var ld = new LobDescriptor(type, options, charLength, byteLength, locatorId, chunk, defaultType); diff --git a/lib/protocol/Writer.js b/lib/protocol/Writer.js index 09878b6..1bb8bb0 100644 --- a/lib/protocol/Writer.js +++ b/lib/protocol/Writer.js @@ -281,7 +281,7 @@ Writer.prototype.finalizeWriteLobRequest = function finalizeWriteLobRequest( // set reabable stream stream = self._lobs[0]; // set lob header - header = new Buffer(WRITE_LOB_REQUEST_HEADER_LENGTH); + header = Buffer.allocUnsafe(WRITE_LOB_REQUEST_HEADER_LENGTH); // set locatorId stream._locatorId.copy(header, 0); // update lob options in header @@ -345,7 +345,7 @@ Writer.prototype.push = function push(buffer) { Writer.prototype.pushNull = function pushNull(type) { /* jshint bitwise:false */ - var buffer = new Buffer([NormalizedTypeCode[type] | 0x80]); + var buffer = Buffer.from([NormalizedTypeCode[type] | 0x80]); this.push(buffer); }; @@ -373,7 +373,7 @@ Writer.prototype[TypeCode.TINYINT] = function writeTinyInt(value) { if (isNaN(value)) { throw createInputError('TINYINT'); } - var buffer = new Buffer(2); + var buffer = Buffer.allocUnsafe(2); buffer[0] = TypeCode.TINYINT; buffer.writeUInt8(value, 1); this.push(buffer); @@ -383,7 +383,7 @@ Writer.prototype[TypeCode.SMALLINT] = function writeSmallInt(value) { if (isNaN(value)) { throw createInputError('SMALLINT'); } - var buffer = new Buffer(3); + var buffer = Buffer.allocUnsafe(3); buffer[0] = TypeCode.SMALLINT; buffer.writeInt16LE(value, 1); this.push(buffer); @@ -393,7 +393,7 @@ Writer.prototype[TypeCode.INT] = function writeInt(value) { if (isNaN(value)) { throw createInputError('INT'); } - var buffer = new Buffer(5); + var buffer = Buffer.allocUnsafe(5); buffer[0] = TypeCode.INT; buffer.writeInt32LE(value, 1); this.push(buffer); @@ -403,7 +403,7 @@ Writer.prototype[TypeCode.BIGINT] = function writeBigInt(value) { if (isNaN(value)) { throw createInputError('BIGINT'); } - var buffer = new Buffer(9); + var buffer = Buffer.allocUnsafe(9); buffer[0] = TypeCode.BIGINT; bignum.writeInt64LE(buffer, value, 1); this.push(buffer); @@ -413,7 +413,7 @@ Writer.prototype[TypeCode.REAL] = function writeReal(value) { if (isNaN(value)) { throw createInputError('REAL'); } - var buffer = new Buffer(5); + var buffer = Buffer.allocUnsafe(5); buffer[0] = TypeCode.REAL; buffer.writeFloatLE(value, 1); this.push(buffer); @@ -423,7 +423,7 @@ Writer.prototype[TypeCode.DOUBLE] = function writeDouble(value) { if (isNaN(value)) { throw createInputError('DOUBLE'); } - var buffer = new Buffer(9); + var buffer = Buffer.allocUnsafe(9); buffer[0] = TypeCode.DOUBLE; buffer.writeDoubleLE(value, 1); this.push(buffer); @@ -438,7 +438,7 @@ Writer.prototype[TypeCode.DECIMAL] = function writeDecimal(value) { } else { throw createInputError('DECIMAL'); } - var buffer = new Buffer(17); + var buffer = Buffer.allocUnsafe(17); buffer[0] = TypeCode.DECIMAL; bignum.writeDec128(buffer, decimal, 1); this.push(buffer); @@ -469,24 +469,24 @@ Writer.prototype[TypeCode.BINARY] = function writeBinary(value) { }; Writer.prototype[TypeCode.BLOB] = function writeBLob(value) { - var buffer = new Buffer(10); + var buffer = Buffer.allocUnsafe(10); buffer.fill(0x00); buffer[0] = TypeCode.BLOB; this.pushLob(buffer, value); }; Writer.prototype[TypeCode.CLOB] = function writeCLob(value) { - var buffer = new Buffer(10); + var buffer = Buffer.allocUnsafe(10); buffer.fill(0x00); buffer[0] = TypeCode.CLOB; if (util.isString(value)) { - value = new Buffer(value, 'ascii'); + value = Buffer.from(value, 'ascii'); } this.pushLob(buffer, value); }; Writer.prototype[TypeCode.NCLOB] = function writeNCLob(value) { - var buffer = new Buffer(10); + var buffer = Buffer.allocUnsafe(10); buffer.fill(0x00); buffer[0] = TypeCode.NCLOB; if (util.isString(value)) { @@ -509,7 +509,7 @@ Writer.prototype[TypeCode.TIME] = function writeTime(value) { } else { throw createInputError('TIME'); } - var buffer = new Buffer(5); + var buffer = Buffer.allocUnsafe(5); buffer[0] = TypeCode.TIME; buffer[1] = hours | 0x80; buffer[2] = minutes; @@ -531,7 +531,7 @@ Writer.prototype[TypeCode.DATE] = function writeDate(value) { } else { throw createInputError('DATE'); } - var buffer = new Buffer(5); + var buffer = Buffer.allocUnsafe(5); buffer[0] = TypeCode.DATE; buffer.writeUInt16LE(year, 1); buffer[2] |= 0x80; @@ -557,7 +557,7 @@ Writer.prototype[TypeCode.TIMESTAMP] = function writeTimestamp(value) { } else { throw createInputError('TIMESTAMP'); } - var buffer = new Buffer(9); + var buffer = Buffer.allocUnsafe(9); buffer[0] = TypeCode.TIMESTAMP; buffer.writeUInt16LE(year, 1); buffer[2] |= 0x80; @@ -622,18 +622,18 @@ function createBinaryOutBuffer(type, value) { var length = value.length; var buffer; if (length <= 245) { - buffer = new Buffer(2 + length); + buffer = Buffer.allocUnsafe(2 + length); buffer[0] = type; buffer[1] = length; value.copy(buffer, 2); } else if (length <= 32767) { - buffer = new Buffer(4 + length); + buffer = Buffer.allocUnsafe(4 + length); buffer[0] = type; buffer[1] = 246; buffer.writeInt16LE(length, 2); value.copy(buffer, 4); } else { - buffer = new Buffer(6 + length); + buffer = Buffer.allocUnsafe(6 + length); buffer[0] = type; buffer[1] = 247; buffer.writeInt32LE(length, 2); diff --git a/lib/protocol/auth/SAML.js b/lib/protocol/auth/SAML.js index 8086ca9..e1366e2 100644 --- a/lib/protocol/auth/SAML.js +++ b/lib/protocol/auth/SAML.js @@ -31,7 +31,7 @@ SAML.prototype.initialize = function initialize(buffer) { }; SAML.prototype.finalData = function finalData() { - return new Buffer(0); + return Buffer.allocUnsafe(0); }; SAML.prototype.finalize = function finalize(buffer) { diff --git a/lib/protocol/auth/SCRAMSHA256.js b/lib/protocol/auth/SCRAMSHA256.js index 43acfc8..6b4a66a 100644 --- a/lib/protocol/auth/SCRAMSHA256.js +++ b/lib/protocol/auth/SCRAMSHA256.js @@ -30,7 +30,7 @@ function SCRAMSHA256(options) { this.name = 'SCRAMSHA256'; this.password = options.password; if (util.isString(this.password)) { - this.password = new Buffer(this.password, 'utf8'); + this.password = Buffer.from(this.password, 'utf8'); } this.clientChallenge = options.clientChallenge || createClientChallenge(); this.clientProof = undefined; @@ -58,7 +58,7 @@ SCRAMSHA256.prototype.finalize = function finalize(buffer) { }; function calculateClientProof(salts, serverKey, clientKey, password) { - var buf = new Buffer(2 + (CLIENT_PROOF_SIZE + 1) * salts.length); + var buf = Buffer.allocUnsafe(2 + (CLIENT_PROOF_SIZE + 1) * salts.length); buf[0] = 0x00; buf.writeInt8(salts.length, 1); var offset = 2; @@ -81,7 +81,7 @@ function scramble(salt, serverKey, clientKey, password) { function xor(a, b) { /* jshint bitwise:false */ - var result = new Buffer(a.length); + var result = Buffer.allocUnsafe(a.length); for (var i = 0; i < a.length; i++) { result[i] = a[i] ^ b[i]; } @@ -91,11 +91,11 @@ function xor(a, b) { function hmac(key, msg) { var hash = crypto.createHmac('sha256', key); hash.update(msg); - return new Buffer(hash.digest(), 'binary'); + return Buffer.from(hash.digest(), 'binary'); } function sha256(msg) { var hash = crypto.createHash('sha256'); hash.update(msg); - return new Buffer(hash.digest(), 'binary'); + return Buffer.from(hash.digest(), 'binary'); } \ No newline at end of file diff --git a/lib/protocol/auth/SessionCookie.js b/lib/protocol/auth/SessionCookie.js index 9c63d6e..ee0b556 100644 --- a/lib/protocol/auth/SessionCookie.js +++ b/lib/protocol/auth/SessionCookie.js @@ -19,10 +19,10 @@ module.exports = SessionCookie; function SessionCookie(options) { this.name = 'SessionCookie'; - var termId = new Buffer(util.cid, 'utf8'); + var termId = Buffer.from(util.cid, 'utf8'); var rawSessionCookie = options.sessionCookie; var length = rawSessionCookie.length + termId.length; - this.sessionCookie = new Buffer.concat([rawSessionCookie, termId], length); + this.sessionCookie = Buffer.concat([rawSessionCookie, termId], length); } SessionCookie.prototype.initialData = function initialData() { @@ -34,7 +34,7 @@ SessionCookie.prototype.initialize = function initialize(buffer) { }; SessionCookie.prototype.finalData = function finalData() { - return new Buffer(0); + return Buffer.allocUnsafe(0); }; SessionCookie.prototype.finalize = function finalize(buffer) { diff --git a/lib/protocol/common/Constants.js b/lib/protocol/common/Constants.js index 6761003..06237ac 100644 --- a/lib/protocol/common/Constants.js +++ b/lib/protocol/common/Constants.js @@ -25,7 +25,7 @@ module.exports = { PART_HEADER_LENGTH: 16, MAX_PACKET_SIZE: Math.pow(2, 17), MAX_RESULT_SET_SIZE: Math.pow(2, 20), - EMPTY_BUFFER: new Buffer(0), + EMPTY_BUFFER: Buffer.allocUnsafe(0), DEFAULT_CONNECT_OPTIONS: [{ name: ConnectOption.CLIENT_LOCALE, value: 'en_US', diff --git a/lib/protocol/data/Fields.js b/lib/protocol/data/Fields.js index 38409b3..2fa6802 100644 --- a/lib/protocol/data/Fields.js +++ b/lib/protocol/data/Fields.js @@ -49,7 +49,7 @@ function write(part, fields) { fields = fields || this; var byteLength = getByteLength(fields); - var buffer = new Buffer(byteLength); + var buffer = Buffer.allocUnsafe(byteLength); buffer.writeUInt16LE(fields.length, 0); offset += 2; @@ -62,7 +62,7 @@ function write(part, fields) { } else if (util.isArray(field)) { data = write({}, field).buffer; } else { - data = new Buffer(field, 'ascii'); + data = Buffer.from(field, 'ascii'); } fieldLength = data.length; if (fieldLength <= 245) { diff --git a/lib/protocol/data/Int32.js b/lib/protocol/data/Int32.js index 2bd5131..be66828 100644 --- a/lib/protocol/data/Int32.js +++ b/lib/protocol/data/Int32.js @@ -39,7 +39,7 @@ function write(part, value) { } part = part || {}; part.argumentCount = getArgumentCount(value); - part.buffer = new Buffer(4); + part.buffer = Buffer.allocUnsafe(4); part.buffer.writeInt32LE(value, 0); return part; } diff --git a/lib/protocol/data/MultilineOptions.js b/lib/protocol/data/MultilineOptions.js index ee8f992..5d63a15 100644 --- a/lib/protocol/data/MultilineOptions.js +++ b/lib/protocol/data/MultilineOptions.js @@ -45,7 +45,7 @@ function write(part, lines) { lines = lines || this; part = part || {}; var byteLength = getByteLength(lines); - var buffer = new Buffer(byteLength); + var buffer = Buffer.allocUnsafe(byteLength); var options; for (var i = 0; i < lines.length; i++) { options = writeOptions({}, lines[i]); diff --git a/lib/protocol/data/Options.js b/lib/protocol/data/Options.js index 3b8ac95..0739b69 100644 --- a/lib/protocol/data/Options.js +++ b/lib/protocol/data/Options.js @@ -87,7 +87,7 @@ function _read(buffer, offset) { case TypeCode.BSTRING: length = buffer.readInt16LE(offset); offset += 2; - option.value = new Buffer(length); + option.value = Buffer.allocUnsafe(length); buffer.copy(option.value, 0, offset, offset + length); offset += length; break; @@ -105,7 +105,7 @@ function write(part, options) { part = part || {}; options = options || this; var byteLength = getByteLength(options); - var buffer = new Buffer(byteLength); + var buffer = Buffer.allocUnsafe(byteLength); var option; for (var i = 0; i < options.length; i++) { option = options[i]; diff --git a/lib/protocol/data/ReadLobRequest.js b/lib/protocol/data/ReadLobRequest.js index 1576972..9ea09b9 100644 --- a/lib/protocol/data/ReadLobRequest.js +++ b/lib/protocol/data/ReadLobRequest.js @@ -30,7 +30,7 @@ function write(part, req) { part = part || {}; req = req || this; - var buffer = new Buffer(READ_LOB_REQUEST_LENGTH); + var buffer = Buffer.allocUnsafe(READ_LOB_REQUEST_LENGTH); if (Buffer.isBuffer(req.locatorId)) { req.locatorId.copy(buffer, offset, 0, 8); } else { @@ -49,7 +49,7 @@ function write(part, req) { function read(part) { var buffer = part.buffer; - var locatorId = new Buffer(8); + var locatorId = Buffer.allocUnsafe(8); buffer.copy(locatorId, 0); return { locatorId: locatorId, diff --git a/lib/protocol/data/TextList.js b/lib/protocol/data/TextList.js index b272559..122a80d 100644 --- a/lib/protocol/data/TextList.js +++ b/lib/protocol/data/TextList.js @@ -26,7 +26,7 @@ function write(part, fields) { fields = fields || this; var byteLength = getByteLength(fields, part.useCesu8); - var buffer = new Buffer(byteLength); + var buffer = Buffer.allocUnsafe(byteLength); var field, fieldLength, data; for (var i = 0; i < fields.length; i++) { diff --git a/lib/protocol/reply/Part.js b/lib/protocol/reply/Part.js index 6ebbae6..f2b4058 100644 --- a/lib/protocol/reply/Part.js +++ b/lib/protocol/reply/Part.js @@ -27,7 +27,7 @@ function Part(kind, attributes, argumentCount, buffer, encoding) { this.attributes = attributes || 0; this.argumentCount = argumentCount || 0; if (util.isString(buffer)) { - this.buffer = new Buffer(buffer, encoding || 'hex'); + this.buffer = Buffer.from(buffer, encoding || 'hex'); } else { this.buffer = buffer; } @@ -65,7 +65,7 @@ function readPart(buffer, offset) { var length = buffer.readInt32LE(offset + 8); offset += PART_HEADER_LENGTH; if (length > 0) { - this.buffer = new Buffer(length); + this.buffer = Buffer.allocUnsafe(length); buffer.copy(this.buffer, 0, offset, offset + length); offset += util.alignLength(length, 8); } @@ -74,7 +74,7 @@ function readPart(buffer, offset) { Part.prototype.toBuffer = function toBuffer(size) { var byteLength = util.alignLength(this.buffer.length, 8); - var buffer = new Buffer(PART_HEADER_LENGTH + byteLength); + var buffer = Buffer.allocUnsafe(PART_HEADER_LENGTH + byteLength); // Part kind, specifies nature of part data buffer.writeInt8(this.kind, 0); // Further attributes of part @@ -97,7 +97,7 @@ Part.prototype.toBuffer = function toBuffer(size) { Part.prototype.inspect = function inspect(options) { var lines = []; options = options || {}; - var offset = new Buffer(options.indentOffset || 0); + var offset = Buffer.allocUnsafe(options.indentOffset || 0); offset.fill(0x20); offset = offset.toString('ascii'); var kindName = common.PartKindName[this.kind]; @@ -116,7 +116,7 @@ Part.prototype.inspect = function inspect(options) { hexstr.push(offset + ' \'' + chunk + '\''); start = end; } - lines.push(offset + ' buffer: new Buffer(\n'); + lines.push(offset + ' buffer: Buffer.from(\n'); lines.push(hexstr.join(' +\n') + ', \'hex\')\n'); } else { lines.push(offset + ' buffer: null\n'); diff --git a/lib/protocol/reply/Segment.js b/lib/protocol/reply/Segment.js index be0fbc5..1f2603e 100644 --- a/lib/protocol/reply/Segment.js +++ b/lib/protocol/reply/Segment.js @@ -92,7 +92,7 @@ Segment.prototype.toBuffer = function toBuffer(size) { return buffer; }); - var header = new Buffer(SEGMENT_HEADER_LENGTH); + var header = Buffer.allocUnsafe(SEGMENT_HEADER_LENGTH); // Length of the segment, including the header header.writeInt32LE(length, 0); diff --git a/lib/protocol/request/Part.js b/lib/protocol/request/Part.js index 92756d8..291a46c 100644 --- a/lib/protocol/request/Part.js +++ b/lib/protocol/request/Part.js @@ -31,7 +31,7 @@ function Part(options) { Part.prototype.toBuffer = function toBuffer(size) { var byteLength = util.alignLength(this.buffer.length, 8); - var buffer = new Buffer(PART_HEADER_LENGTH + byteLength); + var buffer = Buffer.allocUnsafe(PART_HEADER_LENGTH + byteLength); // Part kind, specifies nature of part data buffer.writeInt8(this.kind, 0); // Further attributes of part diff --git a/lib/protocol/request/Segment.js b/lib/protocol/request/Segment.js index 6ca890d..5074c25 100644 --- a/lib/protocol/request/Segment.js +++ b/lib/protocol/request/Segment.js @@ -84,7 +84,7 @@ Segment.prototype.toBuffer = function toBuffer(size) { buffers.push(buffer); } - var header = new Buffer(SEGMENT_HEADER_LENGTH); + var header = Buffer.allocUnsafe(SEGMENT_HEADER_LENGTH); // Length of the segment, including the header header.writeInt32LE(length, 0); // Offset of the segment within the message buffer diff --git a/lib/util/convert.js b/lib/util/convert.js index 0e05208..4317a21 100644 --- a/lib/util/convert.js +++ b/lib/util/convert.js @@ -9,7 +9,7 @@ exports.lengthInCesu8 = lengthInCesu8; function encode(text, useCesu8) { return (useCesu8) ? iconv.encode(text, 'cesu8') : - new Buffer(text, 'utf-8'); + Buffer.from(text, 'utf-8'); } function decode(buffer, useCesu8) { diff --git a/test/acceptance/db.Prepare.js b/test/acceptance/db.Prepare.js index 7eb79d7..6188ac8 100644 --- a/test/acceptance/db.Prepare.js +++ b/test/acceptance/db.Prepare.js @@ -81,7 +81,7 @@ describe('db', function () { }); }, function insert(cb) { - var values = [1, new Buffer('invalid type', 'ascii')]; + var values = [1, Buffer.from('invalid type', 'ascii')]; statement.exec(values, function (err) { err.should.be.instanceof(Error); cb(); diff --git a/test/auth.Manager.js b/test/auth.Manager.js index 25c7e09..1c04fba 100644 --- a/test/auth.Manager.js +++ b/test/auth.Manager.js @@ -20,7 +20,7 @@ var PartKind = lib.common.PartKind; var Fields = lib.data[PartKind.AUTHENTICATION]; var user = 'SYSTEM'; -var emptyBuffer = new Buffer(0); +var emptyBuffer = Buffer.allocUnsafe(0); describe('Auth', function () { @@ -28,15 +28,15 @@ describe('Auth', function () { var method = 'SCRAMSHA256'; var password = 'secret'; - var clientChallenge = new Buffer( + var clientChallenge = Buffer.from( 'edbd7cc8b2f26489d65a7cd51e27f2e73fca227d1ab6aafcac0f428ca4d8e10c' + '19e3e38f3aac51075e67bbe52fdb6103a7c34c8a70908ed5be0b3542705f738c', 'hex'); - var clientProof = new Buffer( + var clientProof = Buffer.from( '000120e47d8f244855b92dc966395d0d282547b54dfd09614d44374df94f293c1a020e', 'hex'); - var salt = new Buffer('80964fa85428ae3a81acd3e686a27933', 'hex'); - var serverChallenge = new Buffer( + var salt = Buffer.from('80964fa85428ae3a81acd3e686a27933', 'hex'); + var serverChallenge = Buffer.from( '41065150117e455fec2f03f6f47c19d405ade50dd65731dc0fb3f7954db62c8a' + 'a67a7e825e1300bee975e74518238c9a', 'hex'); var serverChallengeData = Fields.write({}, [salt, serverChallenge]).buffer; @@ -44,7 +44,7 @@ describe('Auth', function () { it('should get the corresponding authentication method instance', function () { var manager = auth.createManager({ user: user, - password: new Buffer(password, 'utf8'), + password: Buffer.from(password, 'utf8'), clientChallenge: clientChallenge }); var authMethod = manager.getMethod(method); @@ -124,8 +124,8 @@ describe('Auth', function () { describe('#SAML', function () { var method = 'SAML'; - var assertion = new Buffer('3fca227d', 'hex'); - var sessionCookie = new Buffer('fcac0f42', 'hex'); + var assertion = Buffer.from('3fca227d', 'hex'); + var sessionCookie = Buffer.from('fcac0f42', 'hex'); it('should get the corresponding authentication method instance', function () { var manager = auth.createManager({ @@ -151,7 +151,7 @@ describe('Auth', function () { initialData = manager.initialData(); initialData.should.eql(['', method, assertion]); // initialize manager - manager.initialize([method, new Buffer(user, 'utf8')]); + manager.initialize([method, Buffer.from(user, 'utf8')]); manager._authMethod.should.equal(authMethod); // user manager.userFromServer.should.equal(user); @@ -170,7 +170,7 @@ describe('Auth', function () { describe('#SessionCookie', function () { var method = 'SessionCookie'; - var sessionCookie = new Buffer('fcac0f42', 'hex'); + var sessionCookie = Buffer.from('fcac0f42', 'hex'); it('should get the corresponding authentication method instance', function () { var pid = lib.util.pid; @@ -235,7 +235,7 @@ describe('Auth', function () { var manager = auth.createManager({ user: user, password: 'secret', - clientChallenge: new Buffer(4) + clientChallenge: Buffer.allocUnsafe(4) }); (function () { diff --git a/test/data.Binary.js b/test/data.Binary.js index 5cff4ad..02e4b0b 100644 --- a/test/data.Binary.js +++ b/test/data.Binary.js @@ -22,7 +22,7 @@ describe('Data', function () { describe('#Binary', function () { it('should deserialize a Binary Part from buffer', function () { - var buffer = new Buffer([1, 2, 3, 4]); + var buffer = Buffer.from([1, 2, 3, 4]); var part = { argumentCount: 1, buffer: buffer @@ -34,7 +34,7 @@ describe('Data', function () { }); it('should serialize a Binary Part', function () { - var buffer = new Buffer(0); + var buffer = Buffer.allocUnsafe(0); Binary.write.call(buffer).should.eql({ argumentCount: 1, buffer: buffer diff --git a/test/data.Default.js b/test/data.Default.js index 4541a37..c8a82fd 100644 --- a/test/data.Default.js +++ b/test/data.Default.js @@ -22,7 +22,7 @@ describe('Data', function () { describe('#Default', function () { it('should deserialize an Default Part from buffer', function () { - var buffer = new Buffer([1, 2, 3, 4]); + var buffer = Buffer.from([1, 2, 3, 4]); var part = { argumentCount: 1, buffer: buffer, @@ -37,7 +37,7 @@ describe('Data', function () { it('should serialize a Default Part', function () { var part = { argumentCount: 1, - buffer: new Buffer(0), + buffer: Buffer.allocUnsafe(0), length: 16 }; Default.write.call(part).should.eql(part); diff --git a/test/data.Fields.js b/test/data.Fields.js index 49abdeb..587cbdd 100644 --- a/test/data.Fields.js +++ b/test/data.Fields.js @@ -22,21 +22,21 @@ describe('Data', function () { describe('#Fields', function () { var smallFields = [ - new Buffer([1]), - new Buffer([2]) + Buffer.from([1]), + Buffer.from([2]) ]; - var smallBuffer = new Buffer([2, 0, 1, 1, 1, 2]); + var smallBuffer = Buffer.from([2, 0, 1, 1, 1, 2]); var complexFields = [ - new Buffer([1]), [ - new Buffer([2]), - new Buffer([3]) + Buffer.from([1]), [ + Buffer.from([2]), + Buffer.from([3]) ] ]; - var complexBuffer = new Buffer([2, 0, 1, 1, 6, 2, 0, 1, 2, 1, 3]); + var complexBuffer = Buffer.from([2, 0, 1, 1, 6, 2, 0, 1, 2, 1, 3]); function createLargeBuffer(length) { - var buffer = new Buffer(length); + var buffer = Buffer.allocUnsafe(length); buffer.fill(0); return buffer; } @@ -45,10 +45,10 @@ describe('Data', function () { createLargeBuffer(256) ]; var largeBuffer = Buffer.concat([ - new Buffer([2, 0]), - new Buffer([246, 0, 1]), + Buffer.from([2, 0]), + Buffer.from([246, 0, 1]), largeFields[0], - new Buffer([246, 0, 1]), + Buffer.from([246, 0, 1]), largeFields[1] ]); diff --git a/test/data.Int32.js b/test/data.Int32.js index d0d2a6e..91ef24e 100644 --- a/test/data.Int32.js +++ b/test/data.Int32.js @@ -24,7 +24,7 @@ describe('Data', function () { it('should deserialize an Int32 Part from buffer', function () { var part = { argumentCount: 1, - buffer: new Buffer([1, 0, 0, 0]) + buffer: Buffer.from([1, 0, 0, 0]) }; var value = Int32.read(part); value.should.equal(1); @@ -35,7 +35,7 @@ describe('Data', function () { it('should serialize an Int32 Part', function () { Int32.write.call(1).should.eql({ argumentCount: 1, - buffer: new Buffer([1, 0, 0, 0]) + buffer: Buffer.from([1, 0, 0, 0]) }); }); }); diff --git a/test/data.Options.js b/test/data.Options.js index 5284a60..5a352b5 100644 --- a/test/data.Options.js +++ b/test/data.Options.js @@ -21,7 +21,7 @@ describe('Data', function () { var optsPart = { argumentCount: 10, - buffer: new Buffer([ + buffer: Buffer.from([ 0x01, 0x03, 0x67, 0x15, 0x03, 0x00, 0x0b, 0x1d, 0x03, 0x00, 0x58, 0x53, 0x45, 0x0c, 0x03, 0x01, 0x00, 0x00, 0x00, diff --git a/test/data.ParameterMetadata.js b/test/data.ParameterMetadata.js index 498b18b..e6f1d49 100644 --- a/test/data.ParameterMetadata.js +++ b/test/data.ParameterMetadata.js @@ -23,7 +23,7 @@ describe('Data', function () { var paramsPart = { argumentCount: 4, - buffer: new Buffer( + buffer: Buffer.from( '020b01000000000000010000500a0000' + '020b01000b0000000001000000000000' + '020b01001b0000000001000000000000' + diff --git a/test/data.Parameters.js b/test/data.Parameters.js index a45e388..6addfe0 100644 --- a/test/data.Parameters.js +++ b/test/data.Parameters.js @@ -22,16 +22,16 @@ describe('Data', function () { describe('#Parameters', function () { it('should write multiple parameters values', function () { - var value = [new Buffer([1]), new Buffer([2])]; + var value = [Buffer.from([1]), Buffer.from([2])]; var part = Parameters.write({}, value); part.argumentCount.should.equal(2); Parameters.getArgumentCount(value).should.equal(2); - part.buffer.should.eql(new Buffer([1, 2])); + part.buffer.should.eql(Buffer.from([1, 2])); Parameters.getByteLength(value).should.equal(2); }); it('should write one parameters value', function () { - var value = new Buffer([1]); + var value = Buffer.from([1]); Parameters.getArgumentCount(value).should.equal(1); Parameters.getByteLength(value).should.equal(1); Parameters.write({}, value).should.eql({ diff --git a/test/data.ReadLob.js b/test/data.ReadLob.js index d939ef5..994a5cd 100644 --- a/test/data.ReadLob.js +++ b/test/data.ReadLob.js @@ -24,7 +24,7 @@ describe('Data', function () { var reqPart = { argumentCount: 1, - buffer: new Buffer([ + buffer: Buffer.from([ 0x00, 0x00, 0x00, 0x00, 0xf0, 0x18, 0x03, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x0d, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 @@ -39,7 +39,7 @@ describe('Data', function () { var replyPart = { argumentCount: 1, - buffer: new Buffer([ + buffer: Buffer.from([ 0x00, 0x00, 0x00, 0x00, 0xf0, 0x18, 0x03, 0x00, 0x06, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x61, 0x62, 0x63, 0x00, 0x00, 0x00, 0x00 @@ -47,11 +47,11 @@ describe('Data', function () { }; var replyOptions = { - locatorId: new Buffer([0x00, 0x00, 0x00, 0x00, 0xf0, 0x18, 0x03, + locatorId: Buffer.from([0x00, 0x00, 0x00, 0x00, 0xf0, 0x18, 0x03, 0x00 ]), options: 6, - chunk: new Buffer([0x60, 0x61, 0x62, 0x63]) + chunk: Buffer.from([0x60, 0x61, 0x62, 0x63]) }; describe('#ReadLob', function () { diff --git a/test/data.SqlError.js b/test/data.SqlError.js index 7e09332..867e07d 100644 --- a/test/data.SqlError.js +++ b/test/data.SqlError.js @@ -21,7 +21,7 @@ var SqlError = lib.data[PartKind.ERROR]; function serializeError(error) { var length = Buffer.byteLength(error.message); - var buffer = new Buffer(18 + length); + var buffer = Buffer.allocUnsafe(18 + length); buffer.writeInt32LE(error.code, 0); buffer.writeInt32LE(error.position, 4); buffer.writeInt32LE(length, 8); diff --git a/test/data.Text.js b/test/data.Text.js index 849de0d..d3b0e41 100644 --- a/test/data.Text.js +++ b/test/data.Text.js @@ -26,7 +26,7 @@ describe('Data', function () { var part = useCesu8 ? { useCesu8: true } : {}; return util.extend(part, { argumentCount: 1, - buffer: (useCesu8) ? util.convert.encode(command, true) : new Buffer(command, 'utf8') + buffer: (useCesu8) ? util.convert.encode(command, true) : Buffer.from(command, 'utf8') }); } @@ -96,16 +96,16 @@ describe('Data', function () { var textList = ['a', 'b']; var clientInfoPart = { argumentCount: 2, - buffer: new Buffer([1, textList[0].charCodeAt(), 1, textList[1].charCodeAt()]) + buffer: Buffer.from([1, textList[0].charCodeAt(), 1, textList[1].charCodeAt()]) }; var cesu8textList = ['🍩', '🍨']; var cesu8clientInfoPart = { argumentCount: 2, buffer: Buffer.concat([ - new Buffer([6]), + Buffer.from([6]), util.convert.encode(cesu8textList[0], true), - new Buffer([6]), + Buffer.from([6]), util.convert.encode(cesu8textList[1], true) ]), useCesu8: true @@ -118,10 +118,10 @@ describe('Data', function () { var largeClientInfoPart = { argumentCount: 2, buffer: Buffer.concat([ - new Buffer([0xf6, 0xff, 0]), - new Buffer(largeTextList[0], 'utf-8'), - new Buffer([0xf6, 0xff, 0]), - new Buffer(largeTextList[1], 'utf-8') + Buffer.from([0xf6, 0xff, 0]), + Buffer.from(largeTextList[0], 'utf-8'), + Buffer.from([0xf6, 0xff, 0]), + Buffer.from(largeTextList[1], 'utf-8') ]) }; diff --git a/test/data.WriteLob.js b/test/data.WriteLob.js index c57a656..3391319 100644 --- a/test/data.WriteLob.js +++ b/test/data.WriteLob.js @@ -21,7 +21,7 @@ describe('Data', function () { var replyPart = { argumentCount: 3, - buffer: new Buffer([ + buffer: Buffer.from([ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/test/fixtures/parametersData.js b/test/fixtures/parametersData.js index cecf398..efa72cf 100644 --- a/test/fixtures/parametersData.js +++ b/test/fixtures/parametersData.js @@ -25,7 +25,7 @@ exports.MAX_PART_SIZE = MAX_PART_SIZE; exports.DEFAULT = { part: { argumentCount: 1, - buffer: new Buffer( + buffer: Buffer.from( '1e03616c6c' + '1d0464617465' + '1d0464657363' + @@ -63,19 +63,19 @@ exports.DEFAULT = { ] }; -var blob = new Buffer( +var blob = Buffer.from( '89504e470d0a1a0a0000000d494844520000000d0000000e0806000000f47f96d20000' + '000467414d410000b18f0bfc6105000000097048597300000ec100000ec101b8916bed' + '0000001974455874536f667477617265005061696e742e4e45542076332e352e38373b' + '805d00000045494441542853636040030606060b80f83f125e80ae06850fd3a0afaf6f' + '00c350cd981ad14c46b605838dd756a22489b10dc320a8a6787cf4a826030370005135' + '2068971a00fc928ca7dff7607f0000000049454e44ae426082', 'hex'); -var clob = new Buffer('Bjoern Borg', 'ascii'); -var nclob = new Buffer('Bj\u00F6rn Borg', 'utf8'); +var clob = Buffer.from('Bjoern Borg', 'ascii'); +var nclob = Buffer.from('Bj\u00F6rn Borg', 'utf8'); exports.ALL_TYPES = { part: { argumentCount: 1, - buffer: Buffer.concat([new Buffer( + buffer: Buffer.concat([Buffer.from( '0301000000' + '020200' + '0303000000' + @@ -174,7 +174,7 @@ var uuid = '536A6F342D036BA5E10000000A434504'; exports.BINARY = { part: { argumentCount: 1, - buffer: new Buffer('0c10' + uuid + '0c10' + uuid + '0c10' + uuid, 'hex') + buffer: Buffer.from('0c10' + uuid + '0c10' + uuid + '0c10' + uuid, 'hex') }, types: [ TypeCode.BINARY, @@ -182,9 +182,9 @@ exports.BINARY = { TypeCode.BSTRING ], values: [ - new Buffer(uuid, 'hex'), - new Buffer(uuid, 'hex'), - new Buffer(uuid, 'hex') + Buffer.from(uuid, 'hex'), + Buffer.from(uuid, 'hex'), + Buffer.from(uuid, 'hex') ] }; @@ -192,7 +192,7 @@ exports.BINARY = { var logo = fs.readFileSync(path.join(__dirname, 'img', 'logo.png')); function logoBuffer(size) { - var buffer = new Buffer(size); + var buffer = Buffer.allocUnsafe(size); var offset = 15; buffer[0] = TypeCode.INT; buffer.writeInt32LE(1, 1); @@ -222,10 +222,10 @@ exports.EMOJI = { part: { argumentCount: 2, buffer: Buffer.concat([ - new Buffer([0x1e, 0x6]), - new Buffer([0xed, 0xa0, 0xbc, 0xed, 0xbd, 0xa8]), // cesu-8 encoded 🍨 - new Buffer([0x1a, 0x6, 0x6, 0x0, 0x0, 0x0, 0x13, 0x0, 0x0, 0x0]), - new Buffer([0xed, 0xa0, 0xbc, 0xed, 0xbd, 0xa9]) // cesu-8 encoded 🍩 + Buffer.from([0x1e, 0x6]), + Buffer.from([0xed, 0xa0, 0xbc, 0xed, 0xbd, 0xa8]), // cesu-8 encoded 🍨 + Buffer.from([0x1a, 0x6, 0x6, 0x0, 0x0, 0x0, 0x13, 0x0, 0x0, 0x0]), + Buffer.from([0xed, 0xa0, 0xbc, 0xed, 0xbd, 0xa9]) // cesu-8 encoded 🍩 ]) }, types: [ diff --git a/test/fixtures/resultSetData.js b/test/fixtures/resultSetData.js index 2d55bc0..d7a38c9 100644 --- a/test/fixtures/resultSetData.js +++ b/test/fixtures/resultSetData.js @@ -16,7 +16,7 @@ exports.TABLES = { part: { argumentCount: 32, - buffer: new Buffer([ + buffer: Buffer.from([ 0x03, 0x53, 0x59, 0x53, // NVARCHAR 0x0a, 0x52, 0x53, 0x5f, 0x54, 0x41, 0x42, 0x4c, 0x45, 0x53, 0x5f, // NVARCHAR 0x01, 0x06, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, // BIGINT diff --git a/test/fixtures/resultSetMetadata.js b/test/fixtures/resultSetMetadata.js index 1f9f432..fce2c17 100644 --- a/test/fixtures/resultSetMetadata.js +++ b/test/fixtures/resultSetMetadata.js @@ -20,7 +20,7 @@ var ParameterMode = lib.common.ParameterMode; exports.VERSION_AND_CURRENT_USER = { part: { argumentCount: 2, - buffer: new Buffer([ + buffer: Buffer.from([ // first column 0x02, 0x09, diff --git a/test/fixtures/topogolyInformation.js b/test/fixtures/topogolyInformation.js index cc7012a..8525ce5 100644 --- a/test/fixtures/topogolyInformation.js +++ b/test/fixtures/topogolyInformation.js @@ -19,7 +19,7 @@ var TypeCode = lib.common.TypeCode; exports.DEFAULT = { part: { argumentCount: 2, - buffer: new Buffer([ + buffer: Buffer.from([ // first row 0x0b, 0x00, 0x01, 0x1d, 0x08, 0x00, 0x76, 0x65, 0x68, 0x78, 0x73, 0x30, 0x30, 0x31, diff --git a/test/lib.Connection.js b/test/lib.Connection.js index a9ea741..ec73931 100644 --- a/test/lib.Connection.js +++ b/test/lib.Connection.js @@ -307,17 +307,17 @@ describe('Lib', function () { } return reply; }; - connection.receive(new Buffer('noError'), function (err, reply) { + connection.receive(Buffer.from('noError'), function (err, reply) { (!!err).should.be.not.ok; reply.should.equal(replies.noError); }); - connection.receive(new Buffer('errorSegment'), function (err) { + connection.receive(Buffer.from('errorSegment'), function (err) { err.should.equal(replies.errorSegment.error); }); - connection.receive(new Buffer('parseError'), function (err) { + connection.receive(Buffer.from('parseError'), function (err) { err.should.equal(replies.parseError); }); - connection.receive(new Buffer('transactionError'), function (err) { + connection.receive(Buffer.from('transactionError'), function (err) { err.code.should.equal('EHDBTX'); }); }); @@ -546,7 +546,7 @@ describe('Lib', function () { connection._parseReplySegment = function parseReplySegment() { return replySegment; }; - connection.receive(new Buffer(0), function (err, reply) { + connection.receive(Buffer.allocUnsafe(0), function (err, reply) { (!!err).should.be.not.ok; reply.should.equal(replySegment); }); diff --git a/test/lib.ExecuteTask.js b/test/lib.ExecuteTask.js index 63c3090..532fd98 100644 --- a/test/lib.ExecuteTask.js +++ b/test/lib.ExecuteTask.js @@ -21,7 +21,7 @@ var TypeCode = lib.common.TypeCode; var MessageType = lib.common.MessageType; var util = lib.util; var setImmediate = util.setImmediate; -var STATEMENT_ID = new Buffer([1, 0, 0, 0, 0, 0, 0, 0]); +var STATEMENT_ID = Buffer.from([1, 0, 0, 0, 0, 0, 0, 0]); describe('Lib', function () { @@ -168,8 +168,8 @@ describe('Lib', function () { }); it('should run a single task with BLOB type', function (next) { - var buffer = new Buffer(64); - var locatorId = new Buffer([1, 0, 0, 0, 0, 0, 0, 0]); + var buffer = Buffer.allocUnsafe(64); + var locatorId = Buffer.from([1, 0, 0, 0, 0, 0, 0, 0]); createExecuteTask({ parameters: { types: [TypeCode.BLOB], @@ -194,8 +194,8 @@ describe('Lib', function () { }); it('should run a single failing task with BLOB type ', function (next) { - var buffer = new Buffer(64); - var locatorId = new Buffer([1, 0, 0, 0, 0, 0, 0, 0]); + var buffer = Buffer.allocUnsafe(64); + var locatorId = Buffer.from([1, 0, 0, 0, 0, 0, 0, 0]); createExecuteTask({ parameters: { types: [TypeCode.BLOB], @@ -266,7 +266,7 @@ describe('Lib', function () { }); it('should getParameters with read stream error', function (done) { - var buffer = new Buffer(64); + var buffer = Buffer.allocUnsafe(64); var task = createExecuteTask({ parameters: { types: [TypeCode.BLOB], diff --git a/test/lib.Lob.js b/test/lib.Lob.js index a0d0a3f..94ae8c7 100644 --- a/test/lib.Lob.js +++ b/test/lib.Lob.js @@ -21,13 +21,13 @@ var PartKind = lib.common.PartKind; var ReadLobReply = lib.data[PartKind.READ_LOB_REPLY]; var LobOptions = lib.common.LobOptions; var LobSourceType = lib.common.LobSourceType; -var locatorId = new Buffer([1, 0, 0, 0, 0, 0, 0, 0]); +var locatorId = Buffer.from([1, 0, 0, 0, 0, 0, 0, 0]); function createReadLobReply(chunk, isLast) { /* jshint bitwise:false */ var buffer; if (Buffer.isBuffer(chunk) && chunk.length) { - buffer = new Buffer(chunk.length + 16); + buffer = Buffer.allocUnsafe(chunk.length + 16); if (isLast) { buffer[8] = LobOptions.DATA_INCLUDED | LobOptions.LAST_DATA; } else { @@ -36,7 +36,7 @@ function createReadLobReply(chunk, isLast) { buffer.writeInt32LE(chunk.length, 9); chunk.copy(buffer, 16); } else { - buffer = new Buffer(16); + buffer = Buffer.allocUnsafe(16); buffer.fill(0); } locatorId.copy(buffer, 0); @@ -49,7 +49,7 @@ function createReadLobReply(chunk, isLast) { function createLob(err, length) { /* jshint bitwise:false */ var i = 0; - var ld = createReadLobReply(new Buffer([++i])); + var ld = createReadLobReply(Buffer.from([++i])); ld.type = LobSourceType.BLOB; ld.charLength = 0; ld.byteLength = 5; @@ -63,7 +63,7 @@ function createLob(err, length) { return cb(err); } cb(null, { - readLobReply: createReadLobReply(new Buffer([++i]), i >= length) + readLobReply: createReadLobReply(Buffer.from([++i]), i >= length) }); }, 1); } @@ -77,7 +77,7 @@ describe('Lib', function () { it('should read a Lob', function (done) { var lob = createLob(null, 5); lob.read(function (err, buffer) { - buffer.should.eql(new Buffer([1, 2, 3, 4, 5])); + buffer.should.eql(Buffer.from([1, 2, 3, 4, 5])); done(); }); }); @@ -111,7 +111,7 @@ describe('Lib', function () { done(err); }); stream.once('end', function () { - Buffer.concat(chunks).should.eql(new Buffer([1, 2, 3, 4, 5])); + Buffer.concat(chunks).should.eql(Buffer.from([1, 2, 3, 4, 5])); done(); }); }); @@ -133,7 +133,7 @@ describe('Lib', function () { }); it('should receive data in paused state', function (done) { - var ld = createReadLobReply(new Buffer([1])); + var ld = createReadLobReply(Buffer.from([1])); var options = { readSize: 1 }; @@ -144,7 +144,7 @@ describe('Lib', function () { lob.resume(); }, 1); cb(null, { - readLobReply: createReadLobReply(new Buffer([2]), true) + readLobReply: createReadLobReply(Buffer.from([2]), true) }); } var lob = new Lob(readLob, ld, options); @@ -153,14 +153,14 @@ describe('Lib', function () { chunks.push(chunk); }); lob.on('end', function onend() { - Buffer.concat(chunks).should.eql(new Buffer([1, 2])); + Buffer.concat(chunks).should.eql(Buffer.from([1, 2])); done(); }); lob.resume(); }); it('should create a Lob with type NCLOB', function () { - var chunk = new Buffer('e282ac', 'hex'); + var chunk = Buffer.from('e282ac', 'hex'); function readLob() {} var lob = new Lob(readLob, createLobDescriptor(LobSourceType.NCLOB, chunk, 1)); @@ -170,7 +170,7 @@ describe('Lib', function () { }); it('should create a Lob with type NCLOB containing CESU-8 symbols', function () { - var chunk = new Buffer('eda0bcedbda8', 'hex'); // 🍨 + var chunk = Buffer.from('eda0bcedbda8', 'hex'); // 🍨 function readLob() {} var lob = new Lob(readLob, createLobDescriptor(LobSourceType.NCLOB, chunk, 1), { useCesu8: true }); @@ -180,7 +180,7 @@ describe('Lib', function () { }); it('should create a Lob with type CLOB', function () { - var chunk = new Buffer('x', 'ascii'); + var chunk = Buffer.from('x', 'ascii'); function readLob() {} var lob = new Lob(readLob, createLobDescriptor(LobSourceType.CLOB, chunk, 1)); diff --git a/test/lib.Reader.js b/test/lib.Reader.js index a3be99a..74f46da 100644 --- a/test/lib.Reader.js +++ b/test/lib.Reader.js @@ -41,12 +41,12 @@ function createLobBuffer(locatorId, chunk, encoding) { break; } if (!chunk || !chunk.length) { - buffer = new Buffer(2); + buffer = Buffer.allocUnsafe(2); buffer[0] = sourceType; buffer[1] = LobOptions.NULL_INDICATOR; return buffer; } - buffer = new Buffer(32 + chunk.length); + buffer = Buffer.allocUnsafe(32 + chunk.length); buffer[0] = sourceType; buffer[1] = LobOptions.DATA_INCLUDED | LobOptions.LAST_DATA; buffer[2] = buffer[3] = 0; @@ -66,7 +66,7 @@ describe('Lib', function () { it('should read a TinyInt', function () { var len = 1; var offset = 0; - var buffer = new Buffer(1 + (2 * (len + 1))); + var buffer = Buffer.allocUnsafe(1 + (2 * (len + 1))); // null buffer[offset++] = 0; // 1 @@ -90,7 +90,7 @@ describe('Lib', function () { it('should read a SmallInt', function () { var len = 2; var offset = 0; - var buffer = new Buffer(1 + (2 * (len + 1))); + var buffer = Buffer.allocUnsafe(1 + (2 * (len + 1))); // null buffer[offset++] = 0; // -1 @@ -111,7 +111,7 @@ describe('Lib', function () { it('should read a Int', function () { var len = 4; var offset = 0; - var buffer = new Buffer(1 + (2 * (len + 1))); + var buffer = Buffer.allocUnsafe(1 + (2 * (len + 1))); // null buffer[offset++] = 0; // -1 @@ -132,7 +132,7 @@ describe('Lib', function () { it('should read a BigInt', function () { var len = 8; var offset = 0; - var buffer = new Buffer(1 + (2 * (len + 1))); + var buffer = Buffer.allocUnsafe(1 + (2 * (len + 1))); // null buffer[offset++] = 0; // -1 @@ -151,7 +151,7 @@ describe('Lib', function () { }); it('should read a Double', function () { - var buffer = new Buffer([ + var buffer = Buffer.from([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, @@ -168,7 +168,7 @@ describe('Lib', function () { }); it('should read a Float', function () { - var buffer = new Buffer([ + var buffer = Buffer.from([ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x80, 0x7f, 0x00, 0x00, 0x80, 0xff, @@ -185,7 +185,7 @@ describe('Lib', function () { }); it('should read a Decimal', function () { - var buffer = new Buffer(32); + var buffer = Buffer.allocUnsafe(32); buffer.fill(0x00); buffer[15] = 0x70; buffer[16] = 0x01; @@ -198,7 +198,7 @@ describe('Lib', function () { }); it('should read a String in utf-8 encoding', function () { - var buffer = new Buffer([0xff, 4, 0xF0, 0xA4, 0xAD, 0xA2]); + var buffer = Buffer.from([0xff, 4, 0xF0, 0xA4, 0xAD, 0xA2]); var reader = new lib.Reader(buffer); should(reader.readString() === null).ok; reader.readString().should.equal('𤭢'); @@ -206,7 +206,7 @@ describe('Lib', function () { }); it('should read a String in cesu-8 encoding', function () { - var buffer = new Buffer([0xff, 6, 0xed, 0xa0, 0xbc, 0xed, 0xbd, 0xa8]); + var buffer = Buffer.from([0xff, 6, 0xed, 0xa0, 0xbc, 0xed, 0xbd, 0xa8]); var reader = new lib.Reader(buffer, null, true); should(reader.readString() === null).ok; reader.readString().should.equal('🍨'); @@ -214,7 +214,7 @@ describe('Lib', function () { }); it('should read a Binary', function () { - var buffer = new Buffer([0xff, 4, 0xF0, 0xA4, 0xAD, 0xA2]); + var buffer = Buffer.from([0xff, 4, 0xF0, 0xA4, 0xAD, 0xA2]); var reader = new lib.Reader(buffer); should(reader.readBinary() === null).ok; reader.readBinary().should.eql(buffer.slice(2)); @@ -223,7 +223,7 @@ describe('Lib', function () { it('should read 255 Bytes', function () { var len = 255; - var buffer = new Buffer(len + 3); + var buffer = Buffer.allocUnsafe(len + 3); buffer[0] = 0xf6; buffer.writeInt16LE(len, 1); var reader = new lib.Reader(buffer); @@ -233,7 +233,7 @@ describe('Lib', function () { it('should read 32787 Bytes', function () { var len = 32787; - var buffer = new Buffer(len + 5); + var buffer = Buffer.allocUnsafe(len + 5); buffer[0] = 0xf7; buffer.writeInt32LE(len, 1); var reader = new lib.Reader(buffer); @@ -242,7 +242,7 @@ describe('Lib', function () { }); it('should read a Date', function () { - var buffer = new Buffer([ + var buffer = Buffer.from([ 0xff, 0x7f, 0x00, 0x00, 0x01, 0x80, 0x00, 0x01, 0x0f, 0xa7, 0x0b, 0x1f @@ -255,7 +255,7 @@ describe('Lib', function () { }); it('should read a Time', function () { - var buffer = new Buffer([ + var buffer = Buffer.from([ 0x7f, 0xff, 0x00, 0x00, 0x81, 0x01, 0xe8, 0x03 ]); @@ -266,7 +266,7 @@ describe('Lib', function () { }); it('should read a Timestamp', function () { - var buffer = new Buffer([ + var buffer = Buffer.from([ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x01, 0xe8, 0x03, 0xde, 0x87, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, @@ -281,7 +281,7 @@ describe('Lib', function () { }); it('should read a DayDate', function () { - var buffer = new Buffer([ + var buffer = Buffer.from([ 0x00, 0x00, 0x00, 0x00, 0xde, 0xb9, 0x37, 0x00, 0x02, 0x00, 0x00, 0x00 @@ -294,7 +294,7 @@ describe('Lib', function () { }); it('should read a SecondTime', function () { - var buffer = new Buffer([ + var buffer = Buffer.from([ 0x00, 0x00, 0x00, 0x00, 0x82, 0x51, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00 @@ -307,7 +307,7 @@ describe('Lib', function () { }); it('should read a SecondDate', function () { - var buffer = new Buffer(24); + var buffer = Buffer.allocUnsafe(24); buffer.fill(0x00, 0, 8); bignum.writeInt64LE(buffer, 315538070401, 8); bignum.writeInt64LE(buffer, 2, 16); @@ -320,7 +320,7 @@ describe('Lib', function () { it('should read a LongDate', function () { - var buffer = new Buffer(40); + var buffer = Buffer.allocUnsafe(40); buffer.fill(0x00, 0, 8); bignum.writeInt64LE(buffer, '3155380704000000001', 8); bignum.writeInt64LE(buffer, 2, 16); @@ -338,8 +338,8 @@ describe('Lib', function () { it('should read a BLob', function () { /* jshint bitwise:false */ - var locatorId = new Buffer([1, 0, 0, 0, 0, 0, 0, 0]); - var chunk = new Buffer([1, 2, 3, 4, 5, 6, 7, 8]); + var locatorId = Buffer.from([1, 0, 0, 0, 0, 0, 0, 0]); + var chunk = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]); var buffer = createLobBuffer(locatorId, chunk); var reader = new lib.Reader(buffer, lobFactoy); var lob = reader.readBLob(); @@ -352,8 +352,8 @@ describe('Lib', function () { it('should read a CLob', function () { /* jshint bitwise:false */ - var locatorId = new Buffer([1, 0, 0, 0, 0, 0, 0, 0]); - var chunk = new Buffer('12345678', 'ascii'); + var locatorId = Buffer.from([1, 0, 0, 0, 0, 0, 0, 0]); + var chunk = Buffer.from('12345678', 'ascii'); var buffer = createLobBuffer(locatorId, chunk, 'ascii'); var reader = new lib.Reader(buffer, lobFactoy); var lob = reader.readCLob(); diff --git a/test/lib.Result.js b/test/lib.Result.js index 98731dc..fa7b4f2 100644 --- a/test/lib.Result.js +++ b/test/lib.Result.js @@ -41,7 +41,7 @@ function createResultSet(err, rows) { } function createLob(err, buffer) { - var locatorId = new Buffer([1, 0, 0, 0, 0, 0, 0, 0]); + var locatorId = Buffer.from([1, 0, 0, 0, 0, 0, 0, 0]); var lob = new Lob(null, { locatorId: locatorId }); @@ -169,7 +169,7 @@ describe('Lib', function () { var result = createResult(); var part = { argumentCount: 1, - buffer: new Buffer('010d000000', 'hex') + buffer: Buffer.from('010d000000', 'hex') }; result.createOutputParameters(part).should.eql({ X: 13 @@ -177,7 +177,7 @@ describe('Lib', function () { }); it('should create a lob', function () { - var locatorId = new Buffer([1, 0, 0, 0, 0, 0, 0, 0]); + var locatorId = Buffer.from([1, 0, 0, 0, 0, 0, 0, 0]); var result = createResult(); result._connection._readLob = function readLob() {}; @@ -215,7 +215,7 @@ describe('Lib', function () { name: 'Z' }], }); - var _buffer = new Buffer('foo', 'utf8'); + var _buffer = Buffer.from('foo', 'utf8'); var _params = { Z: createLob(null, _buffer) }; @@ -242,7 +242,7 @@ describe('Lib', function () { name: 'Z' }], }); - var _buffer = new Buffer('foo', 'utf8'); + var _buffer = Buffer.from('foo', 'utf8'); var _params = { Z: _buffer }; diff --git a/test/lib.ResultSet.js b/test/lib.ResultSet.js index e81f512..d91a912 100644 --- a/test/lib.ResultSet.js +++ b/test/lib.ResultSet.js @@ -23,7 +23,7 @@ var ResultSet = lib.ResultSet; var Lob = lib.Lob; function writeInt(i) { - var buffer = new Buffer(3); + var buffer = Buffer.allocUnsafe(3); buffer[0] = 1; buffer.writeInt16LE(i, 1); return buffer; @@ -31,7 +31,7 @@ function writeInt(i) { function writeString(str) { var length = Buffer.byteLength(str); - var buffer = new Buffer(length + 1); + var buffer = Buffer.allocUnsafe(length + 1); buffer[0] = length; buffer.write(str, 1); return buffer; @@ -39,7 +39,7 @@ function writeString(str) { function writeLob(locatorId) { /* jshint bitwise:false */ - var buffer = new Buffer(32); + var buffer = Buffer.allocUnsafe(32); buffer.fill(0); buffer[0] = LobSourceType.NCLOB; buffer[1] = LobOptions.DATA_INCLUDED | LobOptions.LAST_DATA; @@ -129,7 +129,7 @@ function createResultSet(rsd, chunks, options) { function createSimpleResultSet(options) { /* jshint bitwise:false */ var rsd = { - id: new Buffer([1, 0, 0, 0, 0, 0, 0, 0]), + id: Buffer.from([1, 0, 0, 0, 0, 0, 0, 0]), metadata: [{ dataType: TypeCode.SMALLINT, columnDisplayName: 'SMALLINT' @@ -173,7 +173,7 @@ function createSimpleResultSet(options) { function createResultSetWithLob(options) { var rsd = { - id: new Buffer([1, 0, 0, 0, 0, 0, 0, 0]), + id: Buffer.from([1, 0, 0, 0, 0, 0, 0, 0]), metadata: [{ dataType: TypeCode.SMALLINT, columnDisplayName: 'SMALLINT' @@ -218,7 +218,7 @@ function createResultSetWithLob(options) { function createResultSetWithoutLob(options) { /* jshint bitwise:false */ var rsd = { - id: new Buffer([1, 0, 0, 0, 0, 0, 0, 0]), + id: Buffer.from([1, 0, 0, 0, 0, 0, 0, 0]), metadata: [{ dataType: TypeCode.SMALLINT, columnDisplayName: 'SMALLINT' @@ -279,7 +279,7 @@ describe('Lib', function () { rs.readSize.should.equal(Lob.MAX_READ_SIZE); // createLob var lob = ResultSet.prototype.createLob.call({}, { - locatorId: new Buffer([1, 0, 0, 0, 0, 0, 0, 0]) + locatorId: Buffer.from([1, 0, 0, 0, 0, 0, 0, 0]) }); lob.should.be.instanceof(Lob); }); @@ -321,15 +321,15 @@ describe('Lib', function () { rows.should.eql([{ SMALLINT: 1, NVARCHAR: 'foo', - NCLOB: new Buffer([47, 0, 0, 0, 0, 0, 0, 0]) + NCLOB: Buffer.from([47, 0, 0, 0, 0, 0, 0, 0]) }, { SMALLINT: 2, NVARCHAR: 'bar', - NCLOB: new Buffer([11, 0, 0, 0, 0, 0, 0, 0]) + NCLOB: Buffer.from([11, 0, 0, 0, 0, 0, 0, 0]) }, { SMALLINT: 3, NVARCHAR: 'abc', - NCLOB: new Buffer([123, 0, 0, 0, 0, 0, 0, 0]) + NCLOB: Buffer.from([123, 0, 0, 0, 0, 0, 0, 0]) }]); rs.finished.should.be.true; rs.closed.should.be.true; @@ -350,15 +350,15 @@ describe('Lib', function () { rows.should.eql([[ 1, 'foo', - new Buffer([47, 0, 0, 0, 0, 0, 0, 0]) + Buffer.from([47, 0, 0, 0, 0, 0, 0, 0]) ], [ 2, 'bar', - new Buffer([11, 0, 0, 0, 0, 0, 0, 0]) + Buffer.from([11, 0, 0, 0, 0, 0, 0, 0]) ], [ 3, 'abc', - new Buffer([123, 0, 0, 0, 0, 0, 0, 0]) + Buffer.from([123, 0, 0, 0, 0, 0, 0, 0]) ]]); rs.finished.should.be.true; rs.closed.should.be.true; @@ -463,7 +463,7 @@ describe('Lib', function () { stream._readableState.objectMode.should.be.false; readSimpleStream(rs, stream, function (err, chunks) { (!err).should.be.ok; - Buffer.concat(chunks).should.eql(new Buffer( + Buffer.concat(chunks).should.eql(Buffer.from( [1, 1, 0, 1, 2, 0, 1, 3, 0, 1, 4, 0, 1, 5, 0] )); rs.finished.should.be.true; diff --git a/test/lib.ResultSetTransform.js b/test/lib.ResultSetTransform.js index 8f4d40c..67b51a2 100644 --- a/test/lib.ResultSetTransform.js +++ b/test/lib.ResultSetTransform.js @@ -21,7 +21,7 @@ var ResultSetTransform = lib.ResultSetTransform; var Transform = util.stream.Transform; function write(rst, str, cb) { - rst.write(new Buffer(str, 'ascii'), 'buffer', cb); + rst.write(Buffer.from(str, 'ascii'), 'buffer', cb); } function createResultSetTransform(options) { @@ -91,7 +91,7 @@ describe('Lib', function () { it('should create a Reader', function () { function parseRow() {} var resultSet = {}; - var chunk = new Buffer(0); + var chunk = Buffer.allocUnsafe(0); var rst = new ResultSetTransform(parseRow, resultSet, { arrayMode: true }); @@ -122,7 +122,7 @@ describe('Lib', function () { rst.on('readable', function () { var value = rst.read(); if (value !== null) { - chunks.push(new Buffer([value])); + chunks.push(Buffer.from([value])); } }); rst.on('end', function () { @@ -145,7 +145,7 @@ describe('Lib', function () { rst.on('readable', function () { var value = rst.read(); if (value !== null) { - chunks.push(new Buffer(value)); + chunks.push(Buffer.from(value)); } }); rst.on('end', function () { @@ -169,7 +169,7 @@ describe('Lib', function () { rst.on('readable', function () { var value = rst.read(); if (value !== null) { - chunks.push(new Buffer(value)); + chunks.push(Buffer.from(value)); } }); rst.on('end', function () { diff --git a/test/lib.Statement.js b/test/lib.Statement.js index 4719c3e..4b3261c 100644 --- a/test/lib.Statement.js +++ b/test/lib.Statement.js @@ -28,7 +28,7 @@ function createStatement(options) { functionCode: FunctionCode.INSERT, rowsAffected: 1 }, - id: new Buffer([1, 0, 0, 0, 0, 0, 0, 0]), + id: Buffer.from([1, 0, 0, 0, 0, 0, 0, 0]), functionCode: FunctionCode.INSERT, parameterMetadata: [{ dataType: TypeCode.INT, diff --git a/test/lib.Writer.js b/test/lib.Writer.js index f4d34e3..f39b81d 100644 --- a/test/lib.Writer.js +++ b/test/lib.Writer.js @@ -88,7 +88,7 @@ describe('Lib', function () { var stream = writer._lobs[0]; stream._readableState.should.have.length(6054); - var locatorId = new Buffer('0100000000000000', 'hex'); + var locatorId = Buffer.from('0100000000000000', 'hex'); writer.update([locatorId]); writer.getWriteLobRequest(SIZE, function (err, part) { @@ -96,7 +96,7 @@ describe('Lib', function () { return done(err); } part.buffer.should.have.length(SIZE); - var exp = new Buffer( + var exp = Buffer.from( '0100000000000000020000000000000000eb030000', 'hex'); part.buffer.slice(0, 21).should.eql(exp); @@ -109,18 +109,18 @@ describe('Lib', function () { var writer = new Writer([TypeCode.BLOB]); var stream = new lib.util.stream.Readable(); stream._chunks = [ - new Buffer('Lorem ', 'ascii'), - new Buffer('ipsum ', 'ascii'), - new Buffer('dolor ', 'ascii'), - new Buffer('sit ', 'ascii'), - new Buffer('amet.', 'ascii'), + Buffer.from('Lorem ', 'ascii'), + Buffer.from('ipsum ', 'ascii'), + Buffer.from('dolor ', 'ascii'), + Buffer.from('sit ', 'ascii'), + Buffer.from('amet.', 'ascii'), null ]; stream._read = function () { this.push(this._chunks.shift()); }; writer._lobs.push(stream); - stream._locatorId = new Buffer([1, 2, 3, 4, 5, 6, 7, 8]); + stream._locatorId = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]); writer.getWriteLobRequest(1024, function (err, part) { if (err) { return done(err); @@ -151,7 +151,7 @@ describe('Lib', function () { it('should set a BLOB value', function () { var writer = new Writer([TypeCode.BLOB]); - var buf = new Buffer([0x48, 0x4B]); + var buf = Buffer.from([0x48, 0x4B]); // write buffer writer.setValues([buf]); writer.length.should.equal(10); @@ -178,7 +178,7 @@ describe('Lib', function () { it('should set a CLOB value', function () { var writer = new Writer([TypeCode.CLOB]); - var buf = new Buffer('EUR', 'ascii'); + var buf = Buffer.from('EUR', 'ascii'); // write buffer writer.setValues([buf]); writer.length.should.equal(10); @@ -191,7 +191,7 @@ describe('Lib', function () { it('should set a NCLOB value', function () { var writer = new Writer([TypeCode.NCLOB]); - var buf = new Buffer([0xe2, 0x82, 0xac]); + var buf = Buffer.from([0xe2, 0x82, 0xac]); // write buffer writer.setValues([buf]); writer.length.should.equal(10); @@ -236,7 +236,7 @@ describe('Lib', function () { var writer = new Writer([TypeCode.BINARY]); var value, length; // tiny - value = new Buffer('tiny', 'ascii'); + value = Buffer.from('tiny', 'ascii'); length = value.length; writer.setValues([value]); writer.length.should.equal(length + 2); @@ -259,7 +259,7 @@ describe('Lib', function () { done) { var writer = new Writer([TypeCode.BLOB]); var stream = new lib.util.stream.Readable(); - var buffer = new Buffer('blob', 'ascii'); + var buffer = Buffer.from('blob', 'ascii'); var size = 10 + buffer.length; stream.push(buffer); stream.push(null); @@ -283,11 +283,11 @@ describe('Lib', function () { done) { var writer = new Writer([TypeCode.BLOB]); var stream = new lib.util.stream.Readable(); - var buffer = new Buffer('blob', 'ascii'); + var buffer = Buffer.from('blob', 'ascii'); var size = 21 + buffer.length; stream.push(buffer); stream.push(null); - stream._locatorId = new Buffer([1, 2, 3, 4, 5, 6, 7, 8]); + stream._locatorId = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]); writer._lobs.push(stream); writer.getWriteLobRequest(size, function (err, part) { part.argumentCount.should.equal(1); @@ -323,7 +323,7 @@ describe('Lib', function () { var writer = new Writer([TypeCode.BLOB]); var stream = new lib.util.stream.Readable(); stream.read = function (size) { - return new Buffer(size + 1); + return Buffer.allocUnsafe(size + 1); }; writer.setValues([stream]); writer.getParameters(64, function (err) { @@ -338,7 +338,7 @@ describe('Lib', function () { var streamError = new Error('stream error'); var writer = new Writer([TypeCode.BLOB]); var stream = new EventEmitter(); - stream._locatorId = new Buffer([1, 2, 3, 4, 5, 6, 7, 8]); + stream._locatorId = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]); stream.read = function () { return null; }; @@ -354,9 +354,9 @@ describe('Lib', function () { function (done) { var writer = new Writer([TypeCode.BLOB]); var stream = new EventEmitter(); - stream._locatorId = new Buffer([1, 2, 3, 4, 5, 6, 7, 8]); + stream._locatorId = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]); stream.read = function (size) { - return new Buffer(size + 1); + return Buffer.allocUnsafe(size + 1); }; writer._lobs.push(stream); writer.getWriteLobRequest(64, function (err) { diff --git a/test/mock/MockSocket.js b/test/mock/MockSocket.js index 7323003..64482f1 100644 --- a/test/mock/MockSocket.js +++ b/test/mock/MockSocket.js @@ -29,11 +29,11 @@ function MockSocket(options) { this.initializationErrorCode = options.initializationErrorCode; var chunk; if (this.invalidInitializationReply) { - chunk = new Buffer(5); + chunk = Buffer.allocUnsafe(5); } else if (this.initializationErrorCode) { chunk = this.initializationErrorCode; } else { - chunk = new Buffer([4, 20, 0, 4, 1, 0, 0, 0]); + chunk = Buffer.from([4, 20, 0, 4, 1, 0, 0, 0]); } this.chunks = [chunk]; } diff --git a/test/mock/data/dbConnectInfo.js b/test/mock/data/dbConnectInfo.js index 2e50e94..a5ef138 100644 --- a/test/mock/data/dbConnectInfo.js +++ b/test/mock/data/dbConnectInfo.js @@ -26,7 +26,7 @@ exports.NOT_CONNECTED = { kind: PartKind.DB_CONNECT_INFO, argumentCount: 3, attributes: 0, - buffer: new Buffer('041c00021d0c0031322e33342e35362e3132330303a8790000', 'hex') + buffer: Buffer.from('041c00021d0c0031322e33342e35362e3132330303a8790000', 'hex') } ] }; @@ -39,7 +39,7 @@ exports.CONNECTED = { kind: PartKind.DB_CONNECT_INFO, argumentCount: 1, attributes: 0, - buffer: new Buffer('041c01', 'hex') + buffer: Buffer.from('041c01', 'hex') } ] }; \ No newline at end of file diff --git a/test/mock/data/execute.js b/test/mock/data/execute.js index 46a44af..a323a03 100644 --- a/test/mock/data/execute.js +++ b/test/mock/data/execute.js @@ -26,13 +26,13 @@ exports['0100000000000000'] = { kind: PartKind.RESULT_SET_ID, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '0100000001000000', 'hex') }, { kind: PartKind.RESULT_SET, argumentCount: 7, attributes: 17, - buffer: new Buffer( + buffer: Buffer.from( '010d00000008746869727465656e010e00000008666f75727465656e010f0000' + '00076669667465656e0110000000077369787465656e01110000000973657665' + '6e7465656e011200000008656967687465656e0113000000086e696e65746565' + @@ -46,13 +46,13 @@ exports['0100000000000000'] = { kind: PartKind.RESULT_SET_ID, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '0100000002000000', 'hex') }, { kind: PartKind.RESULT_SET, argumentCount: 9, attributes: 17, - buffer: new Buffer( + buffer: Buffer.from( '0101000000036f6e6501150000000a7477656e74792d6f6e65011f0000000a74' + '68697274792d6f6e6501290000000a666f757274792d6f6e6501330000000966' + '696674792d6f6e65013d0000000973697874792d6f6e6501470000000b736576' + @@ -70,7 +70,7 @@ exports['0200000000000000'] = { kind: PartKind.RESULT_SET_METADATA, argumentCount: 2, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '020300000a00000000000000ffffffff26000000260000000209000011000000' + '28000000ffffffff4e0000004e000000254e554d535f35323732463941423846' + '464336314532453130303030303030413434323139430141254e554d535f3532' + @@ -80,13 +80,13 @@ exports['0200000000000000'] = { kind: PartKind.RESULT_SET_ID, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '0200000001000000', 'hex') }, { kind: PartKind.RESULT_SET, argumentCount: 3, attributes: 17, - buffer: new Buffer( + buffer: Buffer.from( '0103000000057468726565010400000004666f757201050000000466697665', 'hex') }] @@ -98,7 +98,7 @@ exports['0200000000000000'] = { kind: PartKind.RESULT_SET_METADATA, argumentCount: 2, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '020300000a00000000000000ffffffff26000000260000000209000011000000' + '28000000ffffffff4e0000004e000000254e554d535f35323732463941433846' + '464336314532453130303030303030413434323139430141254e554d535f3532' + @@ -108,13 +108,13 @@ exports['0200000000000000'] = { kind: PartKind.RESULT_SET_ID, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '0200000002000000', 'hex') }, { kind: PartKind.RESULT_SET, argumentCount: 0, attributes: 25, - buffer: new Buffer(0) + buffer: Buffer.allocUnsafe(0) }] } }; @@ -127,13 +127,13 @@ exports['0300000000000000'] = { kind: PartKind.ROWS_AFFECTED, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '01000000', 'hex') }, { kind: PartKind.TRANSACTION_FLAGS, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '011c01', 'hex') }] }, @@ -144,19 +144,19 @@ exports['0300000000000000'] = { kind: PartKind.ROWS_AFFECTED, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '01000000', 'hex') }, { kind: PartKind.WRITE_LOB_REPLY, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '0300000000000000', 'hex') }, { kind: PartKind.TRANSACTION_FLAGS, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '041c01', 'hex') }] }, @@ -167,19 +167,19 @@ exports['0300000000000000'] = { kind: PartKind.ROWS_AFFECTED, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '01000000', 'hex') }, { kind: PartKind.WRITE_LOB_REPLY, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '0300000000000000', 'hex') }, { kind: PartKind.TRANSACTION_FLAGS, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '041c01', 'hex') }] }, @@ -190,13 +190,13 @@ exports['0300000000000000'] = { kind: PartKind.ROWS_AFFECTED, argumentCount: 3, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '010000000100000001000000', 'hex') }, { kind: PartKind.WRITE_LOB_REPLY, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '0300000000000000', 'hex') }] } @@ -210,13 +210,13 @@ exports['0700000000000000'] = { kind: PartKind.RESULT_SET_ID, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '0700000001000000', 'hex') }, { kind: PartKind.RESULT_SET, argumentCount: 1, attributes: 17, - buffer: new Buffer( + buffer: Buffer.from( '0158', 'hex') }] } @@ -231,21 +231,21 @@ exports['e5b25188195d0500'] = { kind: PartKind.ROWS_AFFECTED, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '00000000', 'hex') }, { kind: PartKind.TRANSACTION_FLAGS, argumentCount: 2, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '071c00041c01', 'hex') }, { kind: PartKind.STATEMENT_CONTEXT, argumentCount: 2, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '012144000200000064656366070000000000000000002f646563666c8dd58300' + '00000000e91600000000000000000000000000000000000000000000ffffffff' + '000000000000000002047510000000000000', 'hex') @@ -254,14 +254,14 @@ exports['e5b25188195d0500'] = { kind: PartKind.OUTPUT_PARAMETERS, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '0ceda0bcedbda8eda0bcedbda9', 'hex') }, { kind: PartKind.RESULT_SET_METADATA, argumentCount: 2, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '020b00000a00000000000000ffffffff3d0000003d000000020b000032000000' + '40000000ffffffff7d0000007d0000003c5f5359535f5353325f544d505f5441' + '424c455f3136313032305f455f35383532464338323830323233423141453230' + @@ -273,14 +273,14 @@ exports['e5b25188195d0500'] = { kind: PartKind.RESULT_SET_ID, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '5f09f99527580500', 'hex') }, { kind: PartKind.STATEMENT_CONTEXT, argumentCount: 2, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '012144000200000064656366070000000000000000002f646563666c8dd58300' + '00000000e91600000000000000000000000000000000000000000000ffffffff' + '00000000000000000204ba11000000000000', 'hex') @@ -289,7 +289,7 @@ exports['e5b25188195d0500'] = { kind: PartKind.RESULT_SET, argumentCount: 1, attributes: 17, - buffer: new Buffer( + buffer: Buffer.from( '06eda0bcedbda80ceda0bcedbda8eda0bcedbda9', 'hex') } ] diff --git a/test/mock/data/executeDirect.js b/test/mock/data/executeDirect.js index 69de93f..e5e7e44 100644 --- a/test/mock/data/executeDirect.js +++ b/test/mock/data/executeDirect.js @@ -31,20 +31,20 @@ exports['select * from dummy'] = { kind: PartKind.RESULT_SET_METADATA, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '020800000100000000000000ffffffff06000000060000000544554d4d590544' + '554d4d59', 'hex') }, { kind: PartKind.RESULT_SET_ID, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '0100000000000000', 'hex') }, { kind: PartKind.RESULT_SET, argumentCount: 1, attributes: 17, - buffer: new Buffer( + buffer: Buffer.from( '0158', 'hex') }] }; @@ -56,7 +56,7 @@ exports['select * from numbers order by a'] = { kind: PartKind.RESULT_SET_METADATA, argumentCount: 2, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '020300000a00000000000000ffffffff08000000080000000209000010000000' + '0a000000ffffffff1200000012000000074e554d424552530141074e554d4245' + '52530142', 'hex') @@ -64,13 +64,13 @@ exports['select * from numbers order by a'] = { kind: PartKind.RESULT_SET_ID, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '0200000000000000', 'hex') }, { kind: PartKind.RESULT_SET, argumentCount: 32, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '0100000000047a65726f0101000000036f6e6501020000000374776f01030000' + '00057468726565010400000004666f7572010500000004666976650106000000' + '03736978010700000005736576656e0108000000056569676874010900000004' + @@ -97,7 +97,7 @@ exports['select * from read_numbers_between_view with parameters (' + kind: PartKind.RESULT_SET_METADATA, argumentCount: 2, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '020300000a00000000000000ffffffff1a0000001a0000000209000010000000' + '1c000000ffffffff360000003600000019524541445f4e554d424552535f4245' + '545745454e5f56494557014119524541445f4e554d424552535f424554574545' + @@ -106,19 +106,19 @@ exports['select * from read_numbers_between_view with parameters (' + kind: PartKind.RESULT_SET_ID, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '0300000000000000', 'hex') }, { kind: PartKind.STATEMENT_CONTEXT, argumentCount: 2, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '0121080002000000000000000204cb17000000000000', 'hex') }, { kind: PartKind.RESULT_SET, argumentCount: 3, attributes: 17, - buffer: new Buffer( + buffer: Buffer.from( '0103000000057468726565010400000004666f757201050000000466697665', 'hex' ) }] @@ -131,7 +131,7 @@ exports['select * from images order by name'] = { kind: PartKind.RESULT_SET_METADATA, argumentCount: 2, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '020900001000000000000000ffffffff0700000007000000021b0000ffff0000' + '0c000000ffffffff130000001300000006494d41474553044e414d4506494d41' + '474553054244415441', 'hex') @@ -139,7 +139,7 @@ exports['select * from images order by name'] = { kind: PartKind.RESULT_SET_ID, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '0400000000000000', 'hex') }, { kind: PartKind.RESULT_SET, @@ -155,12 +155,12 @@ exports['select * from images order by name'] = { function getImageBuffer(i, length) { /* jshint bitwise:false */ length = length || 1024; - var name = new Buffer(' ' + IMAGES[i].NAME, 'ascii'); + var name = Buffer.from(' ' + IMAGES[i].NAME, 'ascii'); name[0] = name.length - 1; var bdata = IMAGES[i].BDATA; var chunkLength = Math.min(length, bdata.length); var chunk = bdata.slice(0, chunkLength); - var buffer = new Buffer(32); + var buffer = Buffer.allocUnsafe(32); buffer[0] = LobSourceType.BLOB; if (chunk.length === bdata.length) { buffer[1] = LobOptions.DATA_INCLUDED | LobOptions.LAST_DATA; diff --git a/test/mock/data/fetch.js b/test/mock/data/fetch.js index 7fd2282..1b595cf 100644 --- a/test/mock/data/fetch.js +++ b/test/mock/data/fetch.js @@ -25,7 +25,7 @@ exports['0200000000000000'] = [{ kind: PartKind.RESULT_SET, argumentCount: 69, attributes: 17, - buffer: new Buffer( + buffer: Buffer.from( '01200000000a7468697274792d74776f01210000000c7468697274792d746872' + '656501220000000b7468697274792d666f757201230000000b7468697274792d' + '6669766501240000000a7468697274792d73697801250000000c746869727479' + diff --git a/test/mock/data/prepare.js b/test/mock/data/prepare.js index 2d1afa6..f866ffa 100644 --- a/test/mock/data/prepare.js +++ b/test/mock/data/prepare.js @@ -25,13 +25,13 @@ exports['select * from numbers where b like ? order by a'] = { kind: PartKind.STATEMENT_ID, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '0100000000000000', 'hex') }, { kind: PartKind.RESULT_SET_METADATA, argumentCount: 2, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '020300000a00000000000000ffffffff08000000080000000109000010000000' + '0a000000ffffffff1200000012000000074e554d424552530141074e554d4245' + '52530142', 'hex') @@ -39,7 +39,7 @@ exports['select * from numbers where b like ? order by a'] = { kind: PartKind.PARAMETER_METADATA, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '02090100ffffffff1000000000000000', 'hex') }] }; @@ -51,13 +51,13 @@ exports['call read_numbers_between (?, ?, ?)'] = { kind: PartKind.STATEMENT_ID, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '0200000000000000', 'hex') }, { kind: PartKind.PARAMETER_METADATA, argumentCount: 2, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '02030100000000000a0000000200ffff02030100020000000a0000000200ffff' + '01410142', 'hex') }] @@ -70,13 +70,13 @@ exports['insert into images values (?, ?)'] = { kind: PartKind.STATEMENT_ID, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '0300000000000000', 'hex') }, { kind: PartKind.PARAMETER_METADATA, argumentCount: 2, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '02090100ffffffff1000000018000000021b0100ffffffff1000000008000000', 'hex') }] @@ -89,13 +89,13 @@ exports['insert into numbers values (?, ?)'] = { kind: PartKind.STATEMENT_ID, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '0400000000000000', 'hex') }, { kind: PartKind.PARAMETER_METADATA, argumentCount: 2, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '02030100ffffffff0a0000000100000002090100ffffffff1000000008000000', 'hex') }] @@ -108,20 +108,20 @@ exports['select * from dummy where dummy = ?'] = { kind: PartKind.STATEMENT_ID, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '0700000000000000', 'hex') }, { kind: PartKind.RESULT_SET_METADATA, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '020800000100000000000000ffffffff06000000060000000544554d4d590544' + '554d4d59', 'hex') }, { kind: PartKind.PARAMETER_METADATA, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '02090100ffffffff1000000008000000', 'hex') }] }; @@ -134,7 +134,7 @@ exports['call concat_strings_proc (?, ?, ?, ?)'] = { kind: PartKind.STATEMENT_CONTEXT, argumentCount: 2, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '012144000100000020292029010000000000000000001b1cea7f0000994e8400' + '00000000e91600000000000000000000000000000000000000000000ffffffff' + '00000000000000000204bb02000000000000', 'hex') @@ -143,14 +143,14 @@ exports['call concat_strings_proc (?, ?, ?, ?)'] = { kind: PartKind.STATEMENT_ID, argumentCount: 1, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( 'e5b25188195d0500', 'hex') }, { kind: PartKind.PARAMETER_METADATA, argumentCount: 3, attributes: 0, - buffer: new Buffer( + buffer: Buffer.from( '020b0100000000000a00000000000000020b0100020000000a00000000000000' + '020b0400040000003200000000000000014101420143', 'hex') } diff --git a/test/mock/data/readLob.js b/test/mock/data/readLob.js index 947f00f..642c90b 100644 --- a/test/mock/data/readLob.js +++ b/test/mock/data/readLob.js @@ -40,7 +40,7 @@ function getBuffer(id, offset, length) { /* jshint bitwise:false, unused:false */ offset = offset || 1025; var bdata = IMAGES[id].BDATA; - var buffer = new Buffer(16); + var buffer = Buffer.allocUnsafe(16); bignum.writeUInt64LE(buffer, id, 0); var start = offset - 1; var end = start + length; diff --git a/test/mock/data/writeLob.js b/test/mock/data/writeLob.js index 007706c..851f775 100644 --- a/test/mock/data/writeLob.js +++ b/test/mock/data/writeLob.js @@ -26,7 +26,7 @@ exports['0300000000000000'] = { kind: PartKind.WRITE_LOB_REPLY, argumentCount: 1, attributes: 0, - buffer: new Buffer('0300000000000000', 'hex') + buffer: Buffer.from('0300000000000000', 'hex') }] }, 6: { @@ -36,7 +36,7 @@ exports['0300000000000000'] = { kind: PartKind.WRITE_LOB_REPLY, argumentCount: 0, attributes: 0, - buffer: new Buffer(0) + buffer: Buffer.allocUnsafe(0) }] } }; \ No newline at end of file diff --git a/test/mock/server.js b/test/mock/server.js index 301fe79..ca4edee 100644 --- a/test/mock/server.js +++ b/test/mock/server.js @@ -146,11 +146,11 @@ function handleAuthenticate(msg) { var fields = Fields.read(msgPart); var user = fields[0]; var algorithm = fields[1].toString('ascii'); - var salt = new Buffer([ + var salt = Buffer.from([ 0x80, 0x96, 0x4f, 0xa8, 0x54, 0x28, 0xae, 0x3a, 0x81, 0xac, 0xd3, 0xe6, 0x86, 0xa2, 0x79, 0x33 ]); - var serverChallenge = new Buffer([ + var serverChallenge = Buffer.from([ 0x41, 0x06, 0x51, 0x50, 0x11, 0x7e, 0x45, 0x5f, 0xec, 0x2f, 0x03, 0xf6, 0xf4, 0x7c, 0x19, 0xd4, 0x05, 0xad, 0xe5, 0x0d, 0xd6, 0x57, 0x31, 0xdc, @@ -319,7 +319,7 @@ function handleCommit(msg) { var segment = new Segment(SegmentKind.REPLY, FunctionCode.COMMIT); var part = new Part(PartKind.TRANSACTION_FLAGS); part.argumentCount = 1; - part.buffer = new Buffer('011c01', 'hex'); + part.buffer = Buffer.from('011c01', 'hex'); segment.push(part); return segment; } @@ -338,7 +338,7 @@ function readMessage(buffer, offset) { kind: buffer[offset + 0], attributes: buffer[offset + 1], argumentCount: buffer.readInt16LE(offset + 2), - buffer: new Buffer(length) + buffer: Buffer.allocUnsafe(length) }; offset += 16; buffer.copy(part.buffer, 0, offset, offset + length); @@ -350,7 +350,7 @@ function readMessage(buffer, offset) { function writeReply(context, replyBuffer) { /* jshint validthis:true */ - var buffer = new Buffer(32); + var buffer = Buffer.allocUnsafe(32); // Session identifier bignum.writeInt64LE(buffer, context.sessionId, 0); // Packet sequence number in this session diff --git a/test/part.StatementContext.js b/test/part.StatementContext.js index 2df7088..5d626a1 100644 --- a/test/part.StatementContext.js +++ b/test/part.StatementContext.js @@ -28,7 +28,7 @@ describe('Part', function () { it('create a valid statement context', function (done) { var statementContext = createStatementContext(); - var statementSequenceInfo = new Buffer([0, 1, 2, 3, 4, 5, 6, + var statementSequenceInfo = Buffer.from([0, 1, 2, 3, 4, 5, 6, 7, , 8, 9 ]); var serverExecutionTime = 1234; diff --git a/test/rep.part.js b/test/rep.part.js index 8e082b5..d23f1d2 100644 --- a/test/rep.part.js +++ b/test/rep.part.js @@ -23,10 +23,10 @@ describe('Rep', function () { describe('#Part', function () { - var data = new Buffer( + var data = Buffer.from( '0c000100000000000400000000000000' + '0100000000000000', 'hex'); - var dataBigArg = new Buffer( + var dataBigArg = Buffer.from( '0c00ffff020000000400000000000000' + '0100000000000000', 'hex'); var buffer = data.slice(PART_HEADER_LENGTH, PART_HEADER_LENGTH + 4); @@ -81,7 +81,7 @@ describe('Rep', function () { ' kind: PartKind.ROWS_AFFECTED,', ' argumentCount: 1,', ' attributes: 0,', - ' buffer: new Buffer(', + ' buffer: Buffer.from(', ' \'01000000\', \'hex\')', '}' ].join('\n')); diff --git a/test/rep.segment.js b/test/rep.segment.js index 91dbfd2..9542390 100644 --- a/test/rep.segment.js +++ b/test/rep.segment.js @@ -25,7 +25,7 @@ describe('Rep', function () { describe('#Segment', function () { - var data = new Buffer( + var data = Buffer.from( '180000000000000000000100000000000000000000000000', 'hex'); it('should create a new Segment', function () { @@ -66,10 +66,10 @@ describe('Rep', function () { (!segment.getPart(1)).should.be.ok; var parts = [{ kind: 1, - buffer: new Buffer([1]) + buffer: Buffer.from([1]) }, { kind: 1, - buffer: new Buffer([2]) + buffer: Buffer.from([2]) }]; segment.parts = parts.slice(0, 1); segment.getPart(1).should.eql(parts[0]); @@ -81,22 +81,22 @@ describe('Rep', function () { var segment = new Segment(); segment.push({ kind: PartKind.COMMAND, - buffer: new Buffer('foo', 'utf8') + buffer: Buffer.from('foo', 'utf8') }); segment.push({ kind: PartKind.COMMAND, - buffer: new Buffer('bar', 'utf8') + buffer: Buffer.from('bar', 'utf8') }); segment.push({ kind: PartKind.COMMAND, - buffer: new Buffer('foobar', 'utf8') + buffer: Buffer.from('foobar', 'utf8') }); var reply = segment.getReply(); reply.command.should.eql(['foo', 'bar', 'foobar']); }); it('should serialize a segment to a buffer', function () { - var part = new Part(PartKind.ROWS_AFFECTED, 0, 1, new Buffer([1, 0, 0, 0])); + var part = new Part(PartKind.ROWS_AFFECTED, 0, 1, Buffer.from([1, 0, 0, 0])); var segment = new Segment(); segment.push(part); var buffer = segment.toBuffer(256); diff --git a/test/req.Authenticate.js b/test/req.Authenticate.js index ea95aa7..5791f95 100644 --- a/test/req.Authenticate.js +++ b/test/req.Authenticate.js @@ -21,7 +21,7 @@ var auth = lib.auth; describe('Req', function () { - var segmentHeader = new Buffer([ + var segmentHeader = Buffer.from([ 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, @@ -33,7 +33,7 @@ describe('Req', function () { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]); - var partHeader = new Buffer([ + var partHeader = Buffer.from([ 0x21, 0x00, 0x01, 0x00, @@ -43,7 +43,7 @@ describe('Req', function () { ]); - var partBuffer = new Buffer([ + var partBuffer = Buffer.from([ 0x03, 0x00, 0x06, 0x53, 0x59, 0x53, 0x54, 0x45, 0x4d, 0x0b, 0x53, 0x43, 0x52, 0x41, 0x4d, 0x53, 0x48, 0x41, 0x32, 0x35, @@ -57,7 +57,7 @@ describe('Req', function () { var options = { user: 'SYSTEM', password: 'secret', - clientChallenge: new Buffer([0x01, 0x02, 0x03, 0x04]) + clientChallenge: Buffer.from([0x01, 0x02, 0x03, 0x04]) }; describe('#authenticate', function () { diff --git a/test/util.bignum.js b/test/util.bignum.js index 7995163..1a30f23 100644 --- a/test/util.bignum.js +++ b/test/util.bignum.js @@ -18,51 +18,51 @@ var lib = require('../lib'); var bignum = lib.util.bignum; function readInt64(hex) { - return bignum.readInt64LE(new Buffer(hex, 'hex'), 0); + return bignum.readInt64LE(Buffer.from(hex, 'hex'), 0); } function writeInt64(value) { - var buffer = new Buffer(8); + var buffer = Buffer.allocUnsafe(8); bignum.writeInt64LE(buffer, value, 0); return buffer.toString('hex'); } function readUInt64(hex) { - return bignum.readUInt64LE(new Buffer(hex, 'hex'), 0); + return bignum.readUInt64LE(Buffer.from(hex, 'hex'), 0); } function writeUInt64(value) { - var buffer = new Buffer(8); + var buffer = Buffer.allocUnsafe(8); bignum.writeUInt64LE(buffer, value, 0); return buffer.toString('hex'); } function readDec128(hex) { - return bignum.readDec128(new Buffer(hex, 'hex'), 0); + return bignum.readDec128(Buffer.from(hex, 'hex'), 0); } function readDecFloat(hex) { - return bignum.readDecFloat(new Buffer(hex, 'hex'), 0); + return bignum.readDecFloat(Buffer.from(hex, 'hex'), 0); } function readDecFixed(hex, frac) { - return bignum.readDecFixed(new Buffer(hex, 'hex'), 0, frac); + return bignum.readDecFixed(Buffer.from(hex, 'hex'), 0, frac); } function writeDec128(value) { - var buffer = new Buffer(16); + var buffer = Buffer.allocUnsafe(16); bignum.writeDec128(buffer, value, 0); return buffer.toString('hex'); } function writeUInt128(value) { - var buffer = new Buffer(16); + var buffer = Buffer.allocUnsafe(16); bignum.writeUInt128LE(buffer, value, 0); return buffer.toString('hex'); } function readUInt128(hex) { - return bignum.readUInt128LE(new Buffer(hex, 'hex'), 0); + return bignum.readUInt128LE(Buffer.from(hex, 'hex'), 0); } describe('Util', function () { diff --git a/test/util.convert.js b/test/util.convert.js index d464838..abeeb5c 100644 --- a/test/util.convert.js +++ b/test/util.convert.js @@ -21,8 +21,8 @@ describe('Util', function () { describe('#convert', function () { var outOfBom = '🍩'; - var outOfBomCesuBuffer = new Buffer([0xed, 0xa0, 0xbc, 0xed, 0xbd, 0xa9]); - var outOfBomUtf8Buffer = new Buffer([0xf0, 0x9f, 0x8d, 0xa9]); + var outOfBomCesuBuffer = Buffer.from([0xed, 0xa0, 0xbc, 0xed, 0xbd, 0xa9]); + var outOfBomUtf8Buffer = Buffer.from([0xf0, 0x9f, 0x8d, 0xa9]); it('should encode in cesu8 if useCesu8 is true', function () { util.convert.encode(outOfBom, true).should.eql(outOfBomCesuBuffer); diff --git a/test/util.index.js b/test/util.index.js index 23c9e23..c09da4b 100644 --- a/test/util.index.js +++ b/test/util.index.js @@ -48,7 +48,7 @@ describe('Util', function () { function emitData() { process.nextTick(function () { if (values.length) { - ds.emit('data', new Buffer([values.shift()])); + ds.emit('data', Buffer.from([values.shift()])); } else { ds.emit('end'); } From f31eed62828b7cbe9bc21961ee076ea546633bec Mon Sep 17 00:00:00 2001 From: Alexander Penev Date: Mon, 11 Mar 2019 13:40:53 +0200 Subject: [PATCH 2/4] Update deps and engine version --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index b0ac215..92d4938 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "./lib/protocol/tcp.js": "./chrome/sockets/tcp.js" }, "engines": { - "node": ">= 0.12" + "node": ">= 6.0" }, "dependencies": { "iconv-lite": "^0.4.18" @@ -35,11 +35,11 @@ "async": "^2.4.1", "chrome-net": "^3.3.0", "concat-stream": "^1.5.1", - "coveralls": "^2.13.1", + "coveralls": "^3.0.3", "fstream": "^1.0.11", "generic-pool": "^2.4.2", "istanbul": "^0.4.4", - "mocha": "^3.4.2", + "mocha": "^6.0.2", "should": "^10.0.0" }, "optionalDependencies": {} From 4a95bad9883ab92e930774fce5610c0bd9ce630c Mon Sep 17 00:00:00 2001 From: Alexander Penev Date: Fri, 22 Mar 2019 09:35:45 +0200 Subject: [PATCH 3/4] Update .travis.yml --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e30b17b..6ea62b8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,6 @@ cache: directories: - node_modules node_js: - - "0.12" - - "4" - "6" - "8" + - "10" From 92a83425b1b607e937ff6f89600e1c321189879d Mon Sep 17 00:00:00 2001 From: Alexander Penev Date: Mon, 25 Mar 2019 15:28:08 +0200 Subject: [PATCH 4/4] Update reads on readable events --- examples/app3.js | 4 ++-- examples/app7.js | 4 ++-- test/acceptance/db.Query.js | 4 ++-- test/lib.Lob.js | 4 ++-- test/lib.ResultSet.js | 8 ++++---- test/lib.ResultSetTransform.js | 12 ++++++------ test/lib.Stringifier.js | 6 +++--- test/util.index.js | 8 ++++++-- 8 files changed, 27 insertions(+), 23 deletions(-) diff --git a/examples/app3.js b/examples/app3.js index 5117f0f..8a0f738 100644 --- a/examples/app3.js +++ b/examples/app3.js @@ -52,8 +52,8 @@ function fetchRows(rs, cb) { function onreadable() { /* jshint validthis:true */ - var chunk = this.read(); - if (chunk) { + var chunk; + while (null !== (chunk = this.read())) { rows.push(chunk); } } diff --git a/examples/app7.js b/examples/app7.js index f1e3c6a..3c95c96 100644 --- a/examples/app7.js +++ b/examples/app7.js @@ -107,8 +107,8 @@ function fetch(rs, cb) { function read() { /* jshint validthis:true */ - var row = this.read(); - if (row) { + var row; + while (null !== (row = this.read())) { rows.push(row); } } diff --git a/test/acceptance/db.Query.js b/test/acceptance/db.Query.js index 341df81..08a620c 100644 --- a/test/acceptance/db.Query.js +++ b/test/acceptance/db.Query.js @@ -73,8 +73,8 @@ describe('db', function () { readable.once('error', function onerror() { done(err); }).on('readable', function onreadable() { - var chunk = this.read(); - if (chunk) { + var chunk; + while (null !== (chunk = this.read())) { rows = rows.concat(chunk); } }).once('end', function onend() { diff --git a/test/lib.Lob.js b/test/lib.Lob.js index 94ae8c7..be53b28 100644 --- a/test/lib.Lob.js +++ b/test/lib.Lob.js @@ -96,8 +96,8 @@ describe('Lib', function () { var stream = lob.createReadStream(); var chunks = []; stream.on('readable', function () { - var chunk = stream.read(); - if (chunk) { + var chunk; + while (null !== (chunk = stream.read())) { chunks.push(chunk); } if (chunks.length === 3) { diff --git a/test/lib.ResultSet.js b/test/lib.ResultSet.js index d91a912..0ecd043 100644 --- a/test/lib.ResultSet.js +++ b/test/lib.ResultSet.js @@ -93,10 +93,10 @@ ConnectionMock.prototype.fetchNext = function fetchNext(options, cb) { function readSimpleStream(rs, stream, cb) { var chunks = []; stream.on('readable', function onreadable() { - var chunk = stream.read(); - if (chunk !== null) { - chunks.push(chunk); - } + var chunk; + while (null !== (chunk = stream.read())) { + chunks.push(chunk); + } }); rs.once('error', function onerror(err) { cb(err); diff --git a/test/lib.ResultSetTransform.js b/test/lib.ResultSetTransform.js index 67b51a2..f218a92 100644 --- a/test/lib.ResultSetTransform.js +++ b/test/lib.ResultSetTransform.js @@ -120,8 +120,8 @@ describe('Lib', function () { }); var chunks = []; rst.on('readable', function () { - var value = rst.read(); - if (value !== null) { + var value; + while ((value = rst.read()) !== null) { chunks.push(Buffer.from([value])); } }); @@ -143,8 +143,8 @@ describe('Lib', function () { }); var chunks = []; rst.on('readable', function () { - var value = rst.read(); - if (value !== null) { + var value; + while ((value = rst.read()) !== null) { chunks.push(Buffer.from(value)); } }); @@ -167,8 +167,8 @@ describe('Lib', function () { }); var chunks = []; rst.on('readable', function () { - var value = rst.read(); - if (value !== null) { + var value; + while ((value = rst.read()) !== null) { chunks.push(Buffer.from(value)); } }); diff --git a/test/lib.Stringifier.js b/test/lib.Stringifier.js index 61ee939..aa34c76 100644 --- a/test/lib.Stringifier.js +++ b/test/lib.Stringifier.js @@ -73,11 +73,11 @@ function testStringifier(chunks, rows, done) { stringifier.on('error', function (err) { done(err); }).on('readable', function () { - var chunk = this.read(); - if (chunk) { + var chunk; + while (null !== (chunk = this.read())) { data += chunk; } - }).on('finish', function () { + }).on('end', function () { JSON.parse(data).should.eql(rows); done(); }); diff --git a/test/util.index.js b/test/util.index.js index c09da4b..5279d89 100644 --- a/test/util.index.js +++ b/test/util.index.js @@ -57,10 +57,14 @@ describe('Util', function () { var chunks = []; readable.on('readable', function () { - var chunk = this.read(); - if (chunk !== null) { + var chunk; + var emit = false; + while (null !== (chunk = this.read())) { var value = chunk[0]; chunks.unshift(value); + emit = true; + } + if (emit) { emitData(); } });