@@ -76,7 +76,7 @@ class ObjectId {
76
76
'Argument passed in must be a single String of 12 bytes or a string of 24 hex characters'
77
77
) ;
78
78
} else if ( valid && typeof id === 'string' && id . length === 24 && hasBufferType ) {
79
- return new ObjectId ( new Buffer ( id , 'hex' ) ) ;
79
+ return new ObjectId ( Buffer . from ( id , 'hex' ) ) ;
80
80
} else if ( valid && typeof id === 'string' && id . length === 24 ) {
81
81
return ObjectId . createFromHexString ( id ) ;
82
82
} else if ( id != null && id . length === 12 ) {
@@ -167,7 +167,7 @@ class ObjectId {
167
167
: process . pid ) % 0xffff ;
168
168
const inc = this . get_inc ( ) ;
169
169
// Buffer used
170
- const buffer = new Buffer ( 12 ) ;
170
+ const buffer = Buffer . alloc ( 12 ) ;
171
171
// Encode time
172
172
buffer [ 3 ] = time & 0xff ;
173
173
buffer [ 2 ] = ( time >> 8 ) & 0xff ;
@@ -278,7 +278,7 @@ class ObjectId {
278
278
* @return {ObjectId } return the created ObjectId
279
279
*/
280
280
static createFromTime ( time ) {
281
- const buffer = new Buffer ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ;
281
+ const buffer = Buffer . from ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ;
282
282
// Encode time into first 4 bytes
283
283
buffer [ 3 ] = time & 0xff ;
284
284
buffer [ 2 ] = ( time >> 8 ) & 0xff ;
@@ -304,7 +304,7 @@ class ObjectId {
304
304
}
305
305
306
306
// Use Buffer.from method if available
307
- if ( hasBufferType ) return new ObjectId ( new Buffer ( string , 'hex' ) ) ;
307
+ if ( hasBufferType ) return new ObjectId ( Buffer . from ( string , 'hex' ) ) ;
308
308
309
309
// Calculate lengths
310
310
const array = new _Buffer ( 12 ) ;
0 commit comments