Skip to content

Commit

Permalink
fix deprecated warnings on Buffer class (#580)
Browse files Browse the repository at this point in the history
Signed-off-by: Denis barbaron <[email protected]>

Signed-off-by: Denis barbaron <[email protected]>
  • Loading branch information
denis99999 authored Sep 16, 2022
1 parent da6c786 commit 878171e
Show file tree
Hide file tree
Showing 8 changed files with 12,779 additions and 12,512 deletions.
2 changes: 1 addition & 1 deletion lib/units/device/plugins/forward/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ module.exports = syrup.serial()
)
return connectService(1)
.then(function(out) {
var header = new Buffer(4)
var header = Buffer.alloc(4)
header.writeUInt16LE(0, 0)
header.writeUInt16LE(forward.devicePort, 2)
out.write(header)
Expand Down
2 changes: 1 addition & 1 deletion lib/units/device/plugins/forward/util/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var HEADER_SIZE = 4

function ForwardReader() {
stream.Transform.call(this)
this._header = new Buffer(HEADER_SIZE)
this._header = Buffer.alloc(HEADER_SIZE)
this._needLength = -HEADER_SIZE
this._target = 0
}
Expand Down
4 changes: 2 additions & 2 deletions lib/units/device/plugins/forward/util/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ForwardWriter.prototype._transform = function(fullChunk, encoding, done) {
do {
length = Math.min(MAX_PACKET_SIZE, chunk.length)

header = new Buffer(HEADER_SIZE)
header = Buffer.alloc(HEADER_SIZE)
header.writeUInt16LE(this._target, 0)
header.writeUInt16LE(length, 2)

Expand All @@ -33,7 +33,7 @@ ForwardWriter.prototype._transform = function(fullChunk, encoding, done) {
}

ForwardWriter.prototype._flush = function(done) {
var header = new Buffer(HEADER_SIZE)
var header = Buffer.alloc(HEADER_SIZE)
header.writeUInt16LE(this._target, 0)
header.writeUInt16LE(0, 2)

Expand Down
24 changes: 12 additions & 12 deletions lib/units/device/plugins/vnc/util/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ VncConnection.prototype.end = function() {
}

VncConnection.prototype.writeFramebufferUpdate = function(rectangles) {
var chunk = new Buffer(4)
var chunk = Buffer.alloc(4)
chunk[0] = VncConnection.SERVER_MESSAGE_FBUPDATE
chunk[1] = 0
chunk.writeUInt16BE(rectangles.length, 2)
this._write(chunk)

rectangles.forEach(function(rect) {
var rchunk = new Buffer(12)
var rchunk = Buffer.alloc(12)
rchunk.writeUInt16BE(rect.xPosition, 0)
rchunk.writeUInt16BE(rect.yPosition, 2)
rchunk.writeUInt16BE(rect.width, 4)
Expand Down Expand Up @@ -171,19 +171,19 @@ VncConnection.prototype._writeServerVersion = function() {
// Yes, we could just format the string instead. Didn't feel like it.
switch (this._serverVersion) {
case VncConnection.V3_003:
this._write(new Buffer('RFB 003.003\n'))
this._write(Buffer.from('RFB 003.003\n'))
break
case VncConnection.V3_007:
this._write(new Buffer('RFB 003.007\n'))
this._write(Buffer.from('RFB 003.007\n'))
break
case VncConnection.V3_008:
this._write(new Buffer('RFB 003.008\n'))
this._write(Buffer.from('RFB 003.008\n'))
break
}
}

VncConnection.prototype._writeSupportedSecurity = function() {
var chunk = new Buffer(1 + this._serverSupportedSecurity.length)
var chunk = Buffer.alloc(1 + this._serverSupportedSecurity.length)

chunk[0] = this._serverSupportedSecurity.length
this._serverSupportedSecurity.forEach(function(security, i) {
Expand All @@ -197,12 +197,12 @@ VncConnection.prototype._writeSecurityResult = function(result, reason) {
var chunk
switch (result) {
case VncConnection.SECURITYRESULT_OK:
chunk = new Buffer(4)
chunk = Buffer.alloc(4)
chunk.writeUInt32BE(result, 0)
this._write(chunk)
break
case VncConnection.SECURITYRESULT_FAIL:
chunk = new Buffer(4 + 4 + reason.length)
chunk = Buffer.alloc(4 + 4 + reason.length)
chunk.writeUInt32BE(result, 0)
chunk.writeUInt32BE(reason.length, 4)
chunk.write(reason, 8, reason.length)
Expand All @@ -213,7 +213,7 @@ VncConnection.prototype._writeSecurityResult = function(result, reason) {

VncConnection.prototype._writeServerInit = function() {
debug('server pixel format', this._serverPixelFormat)
var chunk = new Buffer(2 + 2 + 16 + 4 + this._serverName.length)
var chunk = Buffer.alloc(2 + 2 + 16 + 4 + this._serverName.length)
chunk.writeUInt16BE(this._serverWidth, 0)
chunk.writeUInt16BE(this._serverHeight, 2)
chunk[4] = this._serverPixelFormat.bitsPerPixel
Expand Down Expand Up @@ -459,15 +459,15 @@ VncConnection.prototype._unguardedRead = function() {
}

VncConnection.prototype._parseVersion = function(chunk) {
if (chunk.equals(new Buffer('RFB 003.008\n'))) {
if (chunk.equals(Buffer.from('RFB 003.008\n'))) {
return VncConnection.V3_008
}

if (chunk.equals(new Buffer('RFB 003.007\n'))) {
if (chunk.equals(Buffer.from('RFB 003.007\n'))) {
return VncConnection.V3_007
}

if (chunk.equals(new Buffer('RFB 003.003\n'))) {
if (chunk.equals(Buffer.from('RFB 003.003\n'))) {
return VncConnection.V3_003
}

Expand Down
6 changes: 3 additions & 3 deletions lib/util/vncauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function reverseByteBits(b) {
}

function reverseBufferByteBits(b) {
var result = new Buffer(b.length)
var result = Buffer.alloc(b.length)

for (var i = 0; i < result.length; ++i) {
result[i] = reverseByteBits(b[i])
Expand All @@ -17,7 +17,7 @@ function reverseBufferByteBits(b) {
}

function normalizePassword(password) {
var key = new Buffer(8).fill(0)
var key = Buffer.alloc(8).fill(0)

// Make sure the key is always 8 bytes long. VNC passwords cannot be
// longer than 8 bytes. Shorter passwords are padded with zeroes.
Expand All @@ -28,7 +28,7 @@ function normalizePassword(password) {

function encrypt(challenge, password) {
var key = normalizePassword(password)
var iv = new Buffer(0).fill(0)
var iv = Buffer.alloc(0).fill(0)

// Note: do not call .final(), .update() is the one that gives us the
// desired result.
Expand Down
1 change: 0 additions & 1 deletion lib/wire/messagestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ DelimitingStream.prototype._transform = function(chunk, encoding, done) {

lengthBytes.push(length)

// this.push(new Buffer(lengthBytes))
this.push(Buffer.from(lengthBytes))
this.push(chunk)

Expand Down
2 changes: 1 addition & 1 deletion res/test/protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports.config = {
browser.takeScreenshot().then(function(png) {
var stream = fs.createWriteStream(dashboardReportDirectory + '/' +
browserName + '-' + result.fullName + '.png')
stream.write(new Buffer(png, 'base64'))
stream.write(Buffer.from(png, 'base64'))
stream.end()
})
})
Expand Down
Loading

0 comments on commit 878171e

Please sign in to comment.