Skip to content

Commit

Permalink
fs: only use Buffer.concat in promises.readFile when necessary
Browse files Browse the repository at this point in the history
PR-URL: #37127
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: Zijian Liu <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
addaleax authored and targos committed May 1, 2021
1 parent 6264ac1 commit e582832
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ async function readFileHandle(filehandle, options) {
chunks.push(buffer.slice(0, bytesRead));
} while (!endOfFile);

const result = Buffer.concat(chunks);
const result = chunks.length === 1 ? chunks[0] : Buffer.concat(chunks);

return options.encoding ? result.toString(options.encoding) : result;
}
Expand Down

0 comments on commit e582832

Please sign in to comment.