File tree 1 file changed +5
-3
lines changed
1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -535,6 +535,7 @@ async function readFileHandle(filehandle, options) {
535
535
throw new ERR_FS_FILE_TOO_LARGE ( size ) ;
536
536
537
537
let totalRead = 0 ;
538
+ const noSize = size === 0 ;
538
539
let buffer = Buffer . allocUnsafeSlow ( length ) ;
539
540
let result = '' ;
540
541
let offset = 0 ;
@@ -557,7 +558,7 @@ async function readFileHandle(filehandle, options) {
557
558
558
559
if ( bytesRead === 0 ||
559
560
totalRead === size ||
560
- ( bytesRead !== buffer . length && ! chunkedRead ) ) {
561
+ ( bytesRead !== buffer . length && ! chunkedRead && ! noSize ) ) {
561
562
const singleRead = bytesRead === totalRead ;
562
563
563
564
const bytesToCheck = chunkedRead ? totalRead : bytesRead ;
@@ -567,7 +568,7 @@ async function readFileHandle(filehandle, options) {
567
568
}
568
569
569
570
if ( ! encoding ) {
570
- if ( size === 0 && ! singleRead ) {
571
+ if ( noSize && ! singleRead ) {
571
572
ArrayPrototypePush ( buffers , buffer ) ;
572
573
return Buffer . concat ( buffers , totalRead ) ;
573
574
}
@@ -582,7 +583,8 @@ async function readFileHandle(filehandle, options) {
582
583
}
583
584
584
585
if ( encoding ) {
585
- result += decoder . write ( buffer ) ;
586
+ result += decoder . write ( noSize && bytesRead !== kReadFileUnknownBufferLength ?
587
+ buffer . subarray ( 0 , bytesRead ) : buffer ) ;
586
588
} else if ( size !== 0 ) {
587
589
offset = totalRead ;
588
590
} else {
You can’t perform that action at this time.
0 commit comments