From 186feb45bc9500d07252a1d1fe8c87655ea7837b 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 86e6924ca2104e..951e4ac214a9f2 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -331,7 +331,7 @@ async function readFileHandle(filehandle, options) { ArrayPrototypePush(chunks, 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; }