From 52fb900603070f12c6c5b0bd7ab197aaecb897fa Mon Sep 17 00:00:00 2001 From: Brikaa Date: Sat, 16 Oct 2021 11:55:22 +0200 Subject: [PATCH] Don't read the file twice --- cli/commands/execute.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/commands/execute.js b/cli/commands/execute.js index 4929ccc..0d906bc 100644 --- a/cli/commands/execute.js +++ b/cli/commands/execute.js @@ -245,9 +245,9 @@ async function run_non_interactively(files, argv) { exports.handler = async argv => { const files = [...(argv.files || []), argv.file].map(file_path => { + const buffer = fs.readFileSync(file_path); const encoding = - (fs - .readFileSync(file_path) + (buffer .toString() .split('') .some(x => x.charCodeAt(0) >= 128) && @@ -255,7 +255,7 @@ exports.handler = async argv => { 'utf8'; return { name: path.basename(file_path), - content: fs.readFileSync(file_path).toString(encoding), + content: buffer.toString(encoding), encoding, }; });