@@ -296,7 +296,7 @@ function deserializeObject(
296
296
297
297
// We have a raw value
298
298
if ( raw ) {
299
- value = buffer . slice ( index , index + objectSize ) ;
299
+ value = buffer . subarray ( index , index + objectSize ) ;
300
300
} else {
301
301
let objectOptions = options ;
302
302
if ( ! globalUTFValidation ) {
@@ -374,52 +374,24 @@ function deserializeObject(
374
374
if ( binarySize > buffer . byteLength )
375
375
throw new BSONError ( 'Binary type size larger than document size' ) ;
376
376
377
- // Decode as raw Buffer object if options specifies it
378
- if ( buffer [ 'slice' ] != null ) {
379
- // If we have subtype 2 skip the 4 bytes for the size
380
- if ( subType === Binary . SUBTYPE_BYTE_ARRAY ) {
381
- binarySize = NumberUtils . getInt32LE ( buffer , index ) ;
382
- index += 4 ;
383
- if ( binarySize < 0 )
384
- throw new BSONError ( 'Negative binary type element size found for subtype 0x02' ) ;
385
- if ( binarySize > totalBinarySize - 4 )
386
- throw new BSONError ( 'Binary type with subtype 0x02 contains too long binary size' ) ;
387
- if ( binarySize < totalBinarySize - 4 )
388
- throw new BSONError ( 'Binary type with subtype 0x02 contains too short binary size' ) ;
389
- }
377
+ // If we have subtype 2 skip the 4 bytes for the size
378
+ if ( subType === Binary . SUBTYPE_BYTE_ARRAY ) {
379
+ binarySize = NumberUtils . getInt32LE ( buffer , index ) ;
380
+ index += 4 ;
381
+ if ( binarySize < 0 )
382
+ throw new BSONError ( 'Negative binary type element size found for subtype 0x02' ) ;
383
+ if ( binarySize > totalBinarySize - 4 )
384
+ throw new BSONError ( 'Binary type with subtype 0x02 contains too long binary size' ) ;
385
+ if ( binarySize < totalBinarySize - 4 )
386
+ throw new BSONError ( 'Binary type with subtype 0x02 contains too short binary size' ) ;
387
+ }
390
388
391
- if ( promoteBuffers && promoteValues ) {
392
- value = ByteUtils . toLocalBufferType ( buffer . slice ( index , index + binarySize ) ) ;
393
- } else {
394
- value = new Binary ( buffer . slice ( index , index + binarySize ) , subType ) ;
395
- if ( subType === constants . BSON_BINARY_SUBTYPE_UUID_NEW && UUID . isValid ( value ) ) {
396
- value = value . toUUID ( ) ;
397
- }
398
- }
389
+ if ( promoteBuffers && promoteValues ) {
390
+ value = ByteUtils . toLocalBufferType ( buffer . subarray ( index , index + binarySize ) ) ;
399
391
} else {
400
- // If we have subtype 2 skip the 4 bytes for the size
401
- if ( subType === Binary . SUBTYPE_BYTE_ARRAY ) {
402
- binarySize = NumberUtils . getInt32LE ( buffer , index ) ;
403
- index += 4 ;
404
- if ( binarySize < 0 )
405
- throw new BSONError ( 'Negative binary type element size found for subtype 0x02' ) ;
406
- if ( binarySize > totalBinarySize - 4 )
407
- throw new BSONError ( 'Binary type with subtype 0x02 contains too long binary size' ) ;
408
- if ( binarySize < totalBinarySize - 4 )
409
- throw new BSONError ( 'Binary type with subtype 0x02 contains too short binary size' ) ;
410
- }
411
-
412
- if ( promoteBuffers && promoteValues ) {
413
- value = ByteUtils . allocateUnsafe ( binarySize ) ;
414
- // Copy the data
415
- for ( i = 0 ; i < binarySize ; i ++ ) {
416
- value [ i ] = buffer [ index + i ] ;
417
- }
418
- } else {
419
- value = new Binary ( buffer . slice ( index , index + binarySize ) , subType ) ;
420
- if ( subType === constants . BSON_BINARY_SUBTYPE_UUID_NEW && UUID . isValid ( value ) ) {
421
- value = value . toUUID ( ) ;
422
- }
392
+ value = new Binary ( buffer . subarray ( index , index + binarySize ) , subType ) ;
393
+ if ( subType === constants . BSON_BINARY_SUBTYPE_UUID_NEW && UUID . isValid ( value ) ) {
394
+ value = value . toUUID ( ) ;
423
395
}
424
396
}
425
397
0 commit comments