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 BethGriggs committed Apr 27, 2020
1 parent a133ac1 commit baa8231
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) {
do {
const { bytesWritten } =
await write(filehandle, data, 0,
MathMin(16384, data.length));
MathMin(kWriteFileMaxChunkSize, data.length));
remaining -= bytesWritten;
data = data.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 baa8231

Please sign in to comment.