From 900edd8e017d86cb2b55064976b7b3e7d3217d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Thu, 28 Nov 2024 13:00:52 +0100 Subject: [PATCH] fs: lazily load ReadFileContext PR-URL: https://github.com/nodejs/node/pull/55998 Reviewed-By: Yagiz Nizipli Reviewed-By: LiviaMedeiros Reviewed-By: Luigi Pinca Reviewed-By: Jason Zhang --- lib/fs.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/fs.js b/lib/fs.js index 9292826c3e2617..45b664b21ec84e 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -162,6 +162,7 @@ let WriteStream; let rimraf; let rimrafSync; let kResistStopPropagation; +let ReadFileContext; // These have to be separate because of how graceful-fs happens to do it's // monkeypatching. @@ -363,7 +364,7 @@ function readFile(path, options, callback) { callback ||= options; validateFunction(callback, 'cb'); options = getOptions(options, { flag: 'r' }); - const ReadFileContext = require('internal/fs/read/context'); + ReadFileContext ??= require('internal/fs/read/context'); const context = new ReadFileContext(callback, options.encoding); context.isUserFd = isFd(path); // File descriptor ownership