From e582832643f90ef2a82ebc3b10e0ad5814ff5d7b Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 29 Jan 2021 14:43:08 +0100 Subject: [PATCH] fs: only use Buffer.concat in promises.readFile when necessary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/37127 Reviewed-By: Antoine du Hamel Reviewed-By: Colin Ihrig Reviewed-By: Darshan Sen Reviewed-By: Zijian Liu Reviewed-By: Benjamin Gruenbaum Reviewed-By: Juan José Arboleda Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- lib/internal/fs/promises.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index ccac60477ff83c..d989f8818ca786 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -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; }