@@ -457,7 +457,11 @@ function readFileAfterStat(err) {
457
457
return context . close ( err ) ;
458
458
}
459
459
460
- context . buffer = Buffer . allocUnsafeSlow ( size ) ;
460
+ try {
461
+ context . buffer = Buffer . allocUnsafeSlow ( size ) ;
462
+ } catch ( err ) {
463
+ return context . close ( err ) ;
464
+ }
461
465
context . read ( ) ;
462
466
}
463
467
@@ -492,27 +496,21 @@ function readFileAfterClose(err) {
492
496
if ( context . err || err )
493
497
return callback ( context . err || err ) ;
494
498
495
- if ( context . size === 0 )
496
- buffer = Buffer . concat ( context . buffers , context . pos ) ;
497
- else if ( context . pos < context . size )
498
- buffer = context . buffer . slice ( 0 , context . pos ) ;
499
- else
500
- buffer = context . buffer ;
501
-
502
- if ( context . encoding ) {
503
- return tryToString ( buffer , context . encoding , callback ) ;
504
- }
505
-
506
- callback ( null , buffer ) ;
507
- }
508
-
509
- function tryToString ( buf , encoding , callback ) {
510
499
try {
511
- buf = buf . toString ( encoding ) ;
500
+ if ( context . size === 0 )
501
+ buffer = Buffer . concat ( context . buffers , context . pos ) ;
502
+ else if ( context . pos < context . size )
503
+ buffer = context . buffer . slice ( 0 , context . pos ) ;
504
+ else
505
+ buffer = context . buffer ;
506
+
507
+ if ( context . encoding )
508
+ buffer = buffer . toString ( context . encoding ) ;
512
509
} catch ( err ) {
513
510
return callback ( err ) ;
514
511
}
515
- callback ( null , buf ) ;
512
+
513
+ callback ( null , buffer ) ;
516
514
}
517
515
518
516
function tryStatSync ( fd , isUserFd ) {
0 commit comments