@@ -100,7 +100,7 @@ function Binary(type, jsValue, buffer) {
100
100
size ::= uint16 | uint32
101
101
*/
102
102
Binary . prototype . writeHeader = function ( count , size ) {
103
- var buffer = new Buffer ( this . isLarge ? 8 : 4 ) ;
103
+ var buffer = Buffer . alloc ( this . isLarge ? 8 : 4 ) ;
104
104
if ( this . isLarge ) {
105
105
buffer . writeUInt32LE ( count , 0 ) ;
106
106
buffer . writeUInt32LE ( size , 4 ) ;
@@ -160,7 +160,7 @@ Binary.prototype.setLarge = function() {
160
160
161
161
Binary . prototype . write = function ( ) {
162
162
return this . isUndefined ? null :
163
- Buffer . concat ( [ new Buffer ( [ this . type ] ) , this . buffer ] , this . buffer . length + 1 ) ;
163
+ Buffer . concat ( [ Buffer . from ( [ this . type ] ) , this . buffer ] , this . buffer . length + 1 ) ;
164
164
} ;
165
165
166
166
@@ -197,7 +197,7 @@ VariableLength.prototype.serialize = function() {
197
197
lengthArray . push ( byte ) ;
198
198
} while ( length ) ;
199
199
200
- return new Buffer ( lengthArray ) ;
200
+ return Buffer . from ( lengthArray ) ;
201
201
} ;
202
202
203
203
@@ -206,21 +206,21 @@ function serializeString(jsString) {
206
206
var stringBuffer , lengthBuffer , binary , vlen ;
207
207
208
208
binary = new Binary ( TYPE_STRING , jsString ) ;
209
- stringBuffer = new Buffer ( jsString , 'utf8' ) ;
209
+ stringBuffer = Buffer . from ( jsString , 'utf8' ) ;
210
210
vlen = new VariableLength ( stringBuffer . length ) ;
211
211
lengthBuffer = vlen . serialize ( ) ;
212
212
binary . buffer = Buffer . concat ( [ lengthBuffer , stringBuffer ] ) ;
213
213
return binary ;
214
214
}
215
215
216
216
function serializeDouble ( jsNumber ) {
217
- var binary = new Binary ( TYPE_DOUBLE , jsNumber , new Buffer ( 8 ) ) ;
217
+ var binary = new Binary ( TYPE_DOUBLE , jsNumber , Buffer . alloc ( 8 ) ) ;
218
218
binary . buffer . writeDoubleLE ( jsNumber , 0 ) ;
219
219
return binary ;
220
220
}
221
221
222
222
function serializeInt16 ( jsNumber ) {
223
- var binary = new Binary ( TYPE_INT16 , jsNumber , new Buffer ( 2 ) ) ;
223
+ var binary = new Binary ( TYPE_INT16 , jsNumber , Buffer . alloc ( 2 ) ) ;
224
224
if ( jsNumber < 32768 ) {
225
225
binary . buffer . writeInt16LE ( jsNumber , 0 ) ;
226
226
} else {
@@ -231,7 +231,7 @@ function serializeInt16(jsNumber) {
231
231
}
232
232
233
233
function serializeInt32 ( jsNumber ) {
234
- var binary = new Binary ( TYPE_INT32 , jsNumber , new Buffer ( 4 ) ) ;
234
+ var binary = new Binary ( TYPE_INT32 , jsNumber , Buffer . alloc ( 4 ) ) ;
235
235
if ( jsNumber < 2147483648 ) {
236
236
binary . buffer . writeInt32LE ( jsNumber , 0 ) ;
237
237
} else {
@@ -243,7 +243,7 @@ function serializeInt32(jsNumber) {
243
243
244
244
function serializeInt64 ( jsNumber ) {
245
245
var binary = new Binary ( TYPE_INT64 , jsNumber ) ;
246
- binary . buffer = new Buffer ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ;
246
+ binary . buffer = Buffer . from ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ;
247
247
if ( jsNumber < 0 ) {
248
248
assert . ifError ( "Encoding of large negative values is not implemented" ) ;
249
249
} else {
@@ -350,7 +350,7 @@ function List(binary, entrySizeArray, itemConstructor, dataBuffer) {
350
350
this . entrySize = entrySizeArray [ this . parent . type ] ;
351
351
this . ItemConstructor = itemConstructor ;
352
352
this . entries = [ ] ;
353
- this . data = dataBuffer || new Buffer ( "" ) ;
353
+ this . data = dataBuffer || Buffer . from ( "" ) ;
354
354
}
355
355
356
356
List . prototype . push = function ( binaryForm ) {
@@ -363,7 +363,7 @@ List.prototype.writeEntries = function(dataStartPos) {
363
363
var buffer , elemSize , cursor , isLarge ;
364
364
365
365
elemSize = this . entrySize ;
366
- buffer = new Buffer ( this . entries . length * elemSize ) ;
366
+ buffer = Buffer . alloc ( this . entries . length * elemSize ) ;
367
367
cursor = 0 ;
368
368
isLarge = this . parent . isLarge ;
369
369
@@ -448,7 +448,7 @@ function sortKeys(a,b) {
448
448
449
449
/* key ::= utf8-data */
450
450
function serializeKey ( jsString ) {
451
- return new Binary ( BINARY_KEY , jsString , new Buffer ( jsString , 'utf8' ) ) ;
451
+ return new Binary ( BINARY_KEY , jsString , Buffer . from ( jsString , 'utf8' ) ) ;
452
452
}
453
453
454
454
function serializeObject ( jsObject ) {
@@ -509,9 +509,9 @@ function serializeObject(jsObject) {
509
509
510
510
511
511
/* Some pre-fabricated Binary values */
512
- binaryNull = new Binary ( TYPE_LITERAL , null , new Buffer ( [ LITERAL_NULL ] ) ) ;
513
- binaryTrue = new Binary ( TYPE_LITERAL , true , new Buffer ( [ LITERAL_TRUE ] ) ) ;
514
- binaryFalse = new Binary ( TYPE_LITERAL , false , new Buffer ( [ LITERAL_FALSE ] ) ) ;
512
+ binaryNull = new Binary ( TYPE_LITERAL , null , Buffer . from ( [ LITERAL_NULL ] ) ) ;
513
+ binaryTrue = new Binary ( TYPE_LITERAL , true , Buffer . from ( [ LITERAL_TRUE ] ) ) ;
514
+ binaryFalse = new Binary ( TYPE_LITERAL , false , Buffer . from ( [ LITERAL_FALSE ] ) ) ;
515
515
binaryUndefined = new Binary ( TYPE_LITERAL ) ;
516
516
517
517
0 commit comments