From 9121bb301fd31412365d052a9bb005ece38bd4d0 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 2 Dec 2021 07:02:01 +0100 Subject: [PATCH] lib: do not lazy load EOL in blob MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This addresses a comment by loading the EOL from the constants file. Signed-off-by: Ruben Bridgewater PR-URL: https://github.com/nodejs/node/pull/41004 Reviewed-By: James M Snell Reviewed-By: Antoine du Hamel Reviewed-By: Mohammed Keyvanzadeh Reviewed-By: Colin Ihrig Reviewed-By: Tobias Nießen Reviewed-By: Benjamin Gruenbaum Reviewed-By: Luigi Pinca --- lib/internal/blob.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/internal/blob.js b/lib/internal/blob.js index 5fb25e04fe1abe..c3e144b10f26b8 100644 --- a/lib/internal/blob.js +++ b/lib/internal/blob.js @@ -75,7 +75,6 @@ const disallowedTypeCharacters = /[^\u{0020}-\u{007E}]/u; let ReadableStream; let URL; -let EOL; const enc = new TextEncoder(); @@ -94,13 +93,7 @@ function lazyReadableStream(options) { return new ReadableStream(options); } -// TODO(@jasnell): This is annoying but this has to be lazy because -// requiring the 'os' module too early causes building Node.js to -// fail with an unknown reference failure. -function lazyEOL() { - EOL ??= require('os').EOL; - return EOL; -} +const { EOL } = require('internal/constants'); function isBlob(object) { return object?.[kHandle] !== undefined; @@ -115,7 +108,7 @@ function getSource(source, endings) { } else if (!isArrayBufferView(source)) { source = `${source}`; if (endings === 'native') - source = RegExpPrototypeSymbolReplace(/\n|\r\n/g, source, lazyEOL()); + source = RegExpPrototypeSymbolReplace(/\n|\r\n/g, source, EOL); source = enc.encode(source); }