diff --git a/lib/fs.js b/lib/fs.js index 708ee7530d70d9..62295406f1f9dc 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -75,7 +75,6 @@ const { aggregateTwoErrors, codes: { ERR_ACCESS_DENIED, - ERR_FS_FILE_TOO_LARGE, ERR_INVALID_ARG_VALUE, }, } = require('internal/errors'); @@ -101,7 +100,6 @@ const { } = require('internal/util'); const { constants: { - kIoMaxLength, kMaxUserId, }, copyObject, @@ -321,11 +319,6 @@ function readFileAfterStat(err, stats) { // stringify operations vs multiple C++/JS boundary crossings). const size = context.size = isFileType(stats, S_IFREG) ? stats[8] : 0; - if (size > kIoMaxLength) { - err = new ERR_FS_FILE_TOO_LARGE(size); - return context.close(err); - } - try { if (size === 0) { // TODO(BridgeAR): If an encoding is set, use the StringDecoder to concat @@ -402,9 +395,6 @@ function tryCreateBuffer(size, fd, isUserFd) { let threw = true; let buffer; try { - if (size > kIoMaxLength) { - throw new ERR_FS_FILE_TOO_LARGE(size); - } buffer = Buffer.allocUnsafe(size); threw = false; } finally { diff --git a/test/parallel/test-fs-readfile.js b/test/parallel/test-fs-readfile.js index 74731728676b1b..3b464cde943728 100644 --- a/test/parallel/test-fs-readfile.js +++ b/test/parallel/test-fs-readfile.js @@ -6,6 +6,7 @@ const common = require('../common'); const tmpdir = require('../../test/common/tmpdir'); const assert = require('assert'); +const path = require('node:path'); const fs = require('fs'); const prefix = `.removeme-fs-readfile-${process.pid}`; @@ -52,26 +53,21 @@ for (const e of fileInfo) { })); } -// readFile() and readFileSync() should fail if the file is too big. +// Test to verify that readFile() and readFileSync() can handle large files { - const kIoMaxLength = 2 ** 31 - 1; + const kLargeFileSize = 3 * 1024 * 1024 * 1024; // 3 GiB - if (!tmpdir.hasEnoughSpace(kIoMaxLength)) { - // truncateSync() will fail with ENOSPC if there is not enough space. - common.printSkipMessage(`Not enough space in ${tmpdir.path}`); - } else { - const file = tmpdir.resolve(`${prefix}-too-large.txt`); - fs.writeFileSync(file, Buffer.from('0')); - fs.truncateSync(file, kIoMaxLength + 1); + const file = path.join(tmpdir.path, 'temp-large-file.txt'); + fs.writeFileSync(file, Buffer.alloc(1024)); + fs.truncateSync(file, kLargeFileSize); - fs.readFile(file, common.expectsError({ - code: 'ERR_FS_FILE_TOO_LARGE', - name: 'RangeError', - })); - assert.throws(() => { - fs.readFileSync(file); - }, { code: 'ERR_FS_FILE_TOO_LARGE', name: 'RangeError' }); - } + fs.readFile(file, (err, data) => { + if (err) { + console.error('Error reading file:', err); + } else { + console.log('File read successfully:', data.length); + } + }); } {