2020 * IN THE SOFTWARE.
2121 */
2222'use strict' ;
23+ const Buffer = require ( 'buffer' ) . Buffer ;
2324const { spawn } = require ( 'child_process' ) ;
2425const crypto = require ( 'crypto' ) ;
2526const { EventEmitter } = require ( 'events' ) ;
@@ -110,29 +111,29 @@ const ProtocolClient = (function setupClient() {
110111 let additionalLength ;
111112 if ( dataLength > kMaxTwoBytePayloadLength ) {
112113 singleByteLength = kEightBytePayloadLengthField ;
113- additionalLength = new Buffer ( 8 ) ;
114+ additionalLength = Buffer . alloc ( 8 ) ;
114115 let remaining = dataLength ;
115116 for ( let i = 0 ; i < 8 ; ++ i ) {
116117 additionalLength [ 7 - i ] = remaining & 0xFF ;
117118 remaining >>= 8 ;
118119 }
119120 } else if ( dataLength > kMaxSingleBytePayloadLength ) {
120121 singleByteLength = kTwoBytePayloadLengthField ;
121- additionalLength = new Buffer ( 2 ) ;
122+ additionalLength = Buffer . alloc ( 2 ) ;
122123 additionalLength [ 0 ] = ( dataLength & 0xFF00 ) >> 8 ;
123124 additionalLength [ 1 ] = dataLength & 0xFF ;
124125 } else {
125- additionalLength = new Buffer ( 0 ) ;
126+ additionalLength = Buffer . alloc ( 0 ) ;
126127 singleByteLength = dataLength ;
127128 }
128129
129- const header = new Buffer ( [
130+ const header = Buffer . from ( [
130131 kFinalBit | kOpCodeText ,
131132 kMaskBit | singleByteLength ,
132133 ] ) ;
133134
134- const mask = new Buffer ( 4 ) ;
135- const masked = new Buffer ( dataLength ) ;
135+ const mask = Buffer . alloc ( 4 ) ;
136+ const masked = Buffer . alloc ( dataLength ) ;
136137 for ( let i = 0 ; i < dataLength ; ++ i ) {
137138 masked [ i ] = payload [ i ] ^ mask [ i % kMaskingKeyWidthInBytes ] ;
138139 }
@@ -268,7 +269,7 @@ const ProtocolClient = (function setupClient() {
268269 this . _lastId = 0 ;
269270 this . _socket = null ;
270271 this . _pending = { } ;
271- this . _unprocessed = new Buffer ( 0 ) ;
272+ this . _unprocessed = Buffer . alloc ( 0 ) ;
272273 }
273274
274275 callMethod ( method , params ) {
@@ -284,7 +285,7 @@ const ProtocolClient = (function setupClient() {
284285 } ;
285286 const json = JSON . stringify ( data ) ;
286287 debuglog ( '> %s' , json ) ;
287- this . _socket . write ( encodeFrameHybi17 ( new Buffer ( json ) ) ) ;
288+ this . _socket . write ( encodeFrameHybi17 ( Buffer . from ( json ) ) ) ;
288289 } ) ;
289290 }
290291
0 commit comments