diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index 9487f48e841dbd..be8d35e13e97e4 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -1,7 +1,5 @@ 'use strict'; -const kWriteFileMaxChunkSize = 2 ** 14; - const { ArrayPrototypePush, Error, @@ -40,6 +38,7 @@ const { kMaxUserId, kReadFileBufferLength, kReadFileUnknownBufferLength, + kWriteFileMaxChunkSize, }, copyObject, getDirents, diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index 1d4edc0e011e4c..6af79033f452b6 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -126,6 +126,8 @@ const kIoMaxLength = 2 ** 31 - 1; const kReadFileUnknownBufferLength = 64 * 1024; const kReadFileBufferLength = 512 * 1024; +const kWriteFileMaxChunkSize = 512 * 1024; + const kMaxUserId = 2 ** 32 - 1; const isWindows = process.platform === 'win32'; @@ -835,6 +837,7 @@ module.exports = { kMaxUserId, kReadFileBufferLength, kReadFileUnknownBufferLength, + kWriteFileMaxChunkSize, }, assertEncoding, BigIntStats, // for testing diff --git a/test/parallel/test-fs-promises-file-handle-writeFile.js b/test/parallel/test-fs-promises-file-handle-writeFile.js index 46c9019bc8d8dd..6458144657dae9 100644 --- a/test/parallel/test-fs-promises-file-handle-writeFile.js +++ b/test/parallel/test-fs-promises-file-handle-writeFile.js @@ -34,13 +34,17 @@ async function validateWriteFile() { async function doWriteAndCancel() { const filePathForHandle = path.resolve(tmpDir, 'dogs-running.txt'); const fileHandle = await open(filePathForHandle, 'w+'); - const buffer = Buffer.from('dogs running'.repeat(10000), 'utf8'); - const controller = new AbortController(); - const { signal } = controller; - process.nextTick(() => controller.abort()); - await assert.rejects(writeFile(fileHandle, buffer, { signal }), { - name: 'AbortError' - }); + try { + const buffer = Buffer.from('dogs running'.repeat(512 * 1024), 'utf8'); + const controller = new AbortController(); + const { signal } = controller; + process.nextTick(() => controller.abort()); + await assert.rejects(writeFile(fileHandle, buffer, { signal }), { + name: 'AbortError' + }); + } finally { + await fileHandle.close(); + } } const dest = path.resolve(tmpDir, 'tmp.txt');