Skip to content

Commit

Permalink
fs: extract kWriteFileMaxChunkSize constant
Browse files Browse the repository at this point in the history
PR-URL: #32640
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
  • Loading branch information
rickyes authored and BridgeAR committed Apr 28, 2020
1 parent 7bd51fb commit 04b1f63
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
// See https://github.com/libuv/libuv/pull/1501.
const kIoMaxLength = 2 ** 31 - 1;

// Note: This is different from kReadFileBufferLength used for non-promisified
// fs.readFile.
const kReadFileMaxChunkSize = 2 ** 14;
const kWriteFileMaxChunkSize = 2 ** 14;

const {
MathMax,
MathMin,
Expand Down Expand Up @@ -150,16 +155,12 @@ async function writeFileHandle(filehandle, data, options) {
do {
const { bytesWritten } =
await write(filehandle, buffer, 0,
MathMin(16384, buffer.length));
MathMin(kWriteFileMaxChunkSize, buffer.length));
remaining -= bytesWritten;
buffer = buffer.slice(bytesWritten);
} while (remaining > 0);
}

// Note: This is different from kReadFileBufferLength used for non-promisified
// fs.readFile.
const kReadFileMaxChunkSize = 16384;

async function readFileHandle(filehandle, options) {
const statFields = await binding.fstat(filehandle.fd, false, kUsePromises);

Expand Down

0 comments on commit 04b1f63

Please sign in to comment.