Fixed Buffer deprecated warnings when using node >= v10

This commit is contained in:
Nicolas Dextraze
2019-11-01 12:53:24 -07:00
parent 78677ba53e
commit 67dab18d53
8 changed files with 43 additions and 29 deletions

View File

@ -50,12 +50,12 @@ TcpPackage.fromBufferSegment = function(data) {
TcpPackage.prototype.asBuffer = function() {
if ((this.flags & TcpFlags.Authenticated) !== 0) {
var loginBytes = new Buffer(this.login);
var loginBytes = Buffer.from(this.login);
if (loginBytes.length > 255) throw new Error("Login serialized length should be less than 256 bytes.");
var passwordBytes = new Buffer(this.password);
var passwordBytes = Buffer.from(this.password);
if (passwordBytes.length > 255) throw new Error("Password serialized length should be less than 256 bytes.");
var res = new Buffer(MandatorySize + 2 + loginBytes.length + passwordBytes.length + (this.data ? this.data.count : 0));
var res = Buffer.alloc(MandatorySize + 2 + loginBytes.length + passwordBytes.length + (this.data ? this.data.count : 0));
res[CommandOffset] = this.command;
res[FlagsOffset] = this.flags;
guidParse.parse(this.correlationId, res, CorrelationOffset);
@ -69,7 +69,7 @@ TcpPackage.prototype.asBuffer = function() {
return res;
} else {
var res = new Buffer(MandatorySize + (this.data ? this.data.count : 0));
var res = Buffer.alloc(MandatorySize + (this.data ? this.data.count : 0));
res[CommandOffset] = this.command;
res[FlagsOffset] = this.flags;
guidParse.parse(this.correlationId, res, CorrelationOffset);
@ -82,4 +82,4 @@ TcpPackage.prototype.asBufferSegment = function() {
return createBufferSegment(this.asBuffer());
};
module.exports = TcpPackage;
module.exports = TcpPackage;