Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
style: Stop using new Buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Krems committed Nov 18, 2016
1 parent ab45b62 commit 37a711e
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/_inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* IN THE SOFTWARE.
*/
'use strict';
const Buffer = require('buffer').Buffer;
const { spawn } = require('child_process');
const crypto = require('crypto');
const { EventEmitter } = require('events');
Expand Down Expand Up @@ -110,29 +111,29 @@ const ProtocolClient = (function setupClient() {
let additionalLength;
if (dataLength > kMaxTwoBytePayloadLength) {
singleByteLength = kEightBytePayloadLengthField;
additionalLength = new Buffer(8);
additionalLength = Buffer.alloc(8);
let remaining = dataLength;
for (let i = 0; i < 8; ++i) {
additionalLength[7 - i] = remaining & 0xFF;
remaining >>= 8;
}
} else if (dataLength > kMaxSingleBytePayloadLength) {
singleByteLength = kTwoBytePayloadLengthField;
additionalLength = new Buffer(2);
additionalLength = Buffer.alloc(2);
additionalLength[0] = (dataLength & 0xFF00) >> 8;
additionalLength[1] = dataLength & 0xFF;
} else {
additionalLength = new Buffer(0);
additionalLength = Buffer.alloc(0);
singleByteLength = dataLength;
}

const header = new Buffer([
const header = Buffer.from([
kFinalBit | kOpCodeText,
kMaskBit | singleByteLength,
]);

const mask = new Buffer(4);
const masked = new Buffer(dataLength);
const mask = Buffer.alloc(4);
const masked = Buffer.alloc(dataLength);
for (let i = 0; i < dataLength; ++i) {
masked[i] = payload[i] ^ mask[i % kMaskingKeyWidthInBytes];
}
Expand Down Expand Up @@ -268,7 +269,7 @@ const ProtocolClient = (function setupClient() {
this._lastId = 0;
this._socket = null;
this._pending = {};
this._unprocessed = new Buffer(0);
this._unprocessed = Buffer.alloc(0);
}

callMethod(method, params) {
Expand All @@ -284,7 +285,7 @@ const ProtocolClient = (function setupClient() {
};
const json = JSON.stringify(data);
debuglog('> %s', json);
this._socket.write(encodeFrameHybi17(new Buffer(json)));
this._socket.write(encodeFrameHybi17(Buffer.from(json)));
});
}

Expand Down

0 comments on commit 37a711e

Please sign in to comment.