File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -535,6 +535,7 @@ async function readFileHandle(filehandle, options) {
535535 throw new ERR_FS_FILE_TOO_LARGE ( size ) ;
536536
537537 let totalRead = 0 ;
538+ const noSize = size === 0 ;
538539 let buffer = Buffer . allocUnsafeSlow ( length ) ;
539540 let result = '' ;
540541 let offset = 0 ;
@@ -557,7 +558,7 @@ async function readFileHandle(filehandle, options) {
557558
558559 if ( bytesRead === 0 ||
559560 totalRead === size ||
560- ( bytesRead !== buffer . length && ! chunkedRead ) ) {
561+ ( bytesRead !== buffer . length && ! chunkedRead && ! noSize ) ) {
561562 const singleRead = bytesRead === totalRead ;
562563
563564 const bytesToCheck = chunkedRead ? totalRead : bytesRead ;
@@ -567,7 +568,7 @@ async function readFileHandle(filehandle, options) {
567568 }
568569
569570 if ( ! encoding ) {
570- if ( size === 0 && ! singleRead ) {
571+ if ( noSize && ! singleRead ) {
571572 ArrayPrototypePush ( buffers , buffer ) ;
572573 return Buffer . concat ( buffers , totalRead ) ;
573574 }
@@ -582,7 +583,8 @@ async function readFileHandle(filehandle, options) {
582583 }
583584
584585 if ( encoding ) {
585- result += decoder . write ( buffer ) ;
586+ result += decoder . write ( noSize && bytesRead !== kReadFileUnknownBufferLength ?
587+ buffer . subarray ( 0 , bytesRead ) : buffer ) ;
586588 } else if ( size !== 0 ) {
587589 offset = totalRead ;
588590 } else {
Original file line number Diff line number Diff line change @@ -81,6 +81,8 @@ function normalizeEncoding(enc) {
8181function StringDecoder ( encoding ) {
8282 this . encoding = normalizeEncoding ( encoding ) ;
8383 this [ kNativeDecoder ] = Buffer . alloc ( kSize ) ;
84+
85+
8486 this [ kNativeDecoder ] [ kEncodingField ] = encodingsMap [ this . encoding ] ;
8587}
8688
You can’t perform that action at this time.
0 commit comments