File tree Expand file tree Collapse file tree 4 files changed +42
-27
lines changed
Expand file tree Collapse file tree 4 files changed +42
-27
lines changed Original file line number Diff line number Diff line change 2424
2525'use strict' ;
2626
27- // Most platforms don't allow reads or writes >= 2 GB.
28- // See https://github.com/libuv/libuv/pull/1501.
29- const kIoMaxLength = 2 ** 31 - 1 ;
30-
3127// When using FSReqCallback, make sure to create the object only *after* all
3228// parameter validation has happened, so that the objects are not kept in memory
3329// in case they are created but never used due to an exception.
@@ -79,6 +75,10 @@ const { FSReqCallback, statValues } = binding;
7975const { toPathIfFileURL } = require ( 'internal/url' ) ;
8076const internalUtil = require ( 'internal/util' ) ;
8177const {
78+ constants : {
79+ kIoMaxLength,
80+ kMaxUserId,
81+ } ,
8282 copyObject,
8383 Dirent,
8484 getDirents,
@@ -121,8 +121,6 @@ const {
121121 validateInteger,
122122 validateInt32
123123} = require ( 'internal/validators' ) ;
124- // 2 ** 32 - 1
125- const kMaxUserId = 4294967295 ;
126124
127125let truncateWarn = true ;
128126let fs ;
Original file line number Diff line number Diff line change 11'use strict' ;
22
3- // Most platforms don't allow reads or writes >= 2 GB.
4- // See https://github.com/libuv/libuv/pull/1501.
5- const kIoMaxLength = 2 ** 31 - 1 ;
6-
7- // Note: This is different from kReadFileBufferLength used for non-promisified
8- // fs.readFile.
9- const kReadFileMaxChunkSize = 2 ** 14 ;
10- const kWriteFileMaxChunkSize = 2 ** 14 ;
11-
12- // 2 ** 32 - 1
13- const kMaxUserId = 4294967295 ;
14-
153const {
164 Error,
175 MathMax,
@@ -44,6 +32,13 @@ const {
4432const { isArrayBufferView } = require ( 'internal/util/types' ) ;
4533const { rimrafPromises } = require ( 'internal/fs/rimraf' ) ;
4634const {
35+ constants : {
36+ kIoMaxLength,
37+ kMaxUserId,
38+ kReadFileBufferLength,
39+ kReadFileUnknownBufferLength,
40+ kWriteFileMaxChunkSize,
41+ } ,
4742 copyObject,
4843 getDirents,
4944 getOptions,
Original file line number Diff line number Diff line change 44 MathMin,
55} = primordials ;
66
7+ const {
8+ constants : {
9+ kReadFileBufferLength,
10+ kReadFileUnknownBufferLength,
11+ }
12+ } = require ( 'internal/fs/utils' ) ;
13+
714const { Buffer } = require ( 'buffer' ) ;
815
916const { FSReqCallback, close, read } = internalBinding ( 'fs' ) ;
@@ -18,15 +25,6 @@ const lazyDOMException = hideStackFrames((message, name) => {
1825 return new DOMException ( message , name ) ;
1926} ) ;
2027
21- // Use 64kb in case the file type is not a regular file and thus do not know the
22- // actual file size. Increasing the value further results in more frequent over
23- // allocation for small files and consumes CPU time and memory that should be
24- // used else wise.
25- // Use up to 512kb per read otherwise to partition reading big files to prevent
26- // blocking other threads in case the available threads are all in use.
27- const kReadFileUnknownBufferLength = 64 * 1024 ;
28- const kReadFileBufferLength = 512 * 1024 ;
29-
3028function readFileAfterRead ( err , bytesRead ) {
3129 const context = this . context ;
3230
Original file line number Diff line number Diff line change @@ -113,6 +113,23 @@ const kMaximumCopyMode = COPYFILE_EXCL |
113113 COPYFILE_FICLONE |
114114 COPYFILE_FICLONE_FORCE ;
115115
116+ // Most platforms don't allow reads or writes >= 2 GB.
117+ // See https://github.com/libuv/libuv/pull/1501.
118+ const kIoMaxLength = 2 ** 31 - 1 ;
119+
120+ // Use 64kb in case the file type is not a regular file and thus do not know the
121+ // actual file size. Increasing the value further results in more frequent over
122+ // allocation for small files and consumes CPU time and memory that should be
123+ // used else wise.
124+ // Use up to 512kb per read otherwise to partition reading big files to prevent
125+ // blocking other threads in case the available threads are all in use.
126+ const kReadFileUnknownBufferLength = 64 * 1024 ;
127+ const kReadFileBufferLength = 512 * 1024 ;
128+
129+ const kWriteFileMaxChunkSize = 512 * 1024 ;
130+
131+ const kMaxUserId = 2 ** 32 - 1 ;
132+
116133const isWindows = process . platform === 'win32' ;
117134
118135let fs ;
@@ -815,6 +832,13 @@ const validatePosition = hideStackFrames((position, name) => {
815832} ) ;
816833
817834module . exports = {
835+ constants : {
836+ kIoMaxLength,
837+ kMaxUserId,
838+ kReadFileBufferLength,
839+ kReadFileUnknownBufferLength,
840+ kWriteFileMaxChunkSize,
841+ } ,
818842 assertEncoding,
819843 BigIntStats, // for testing
820844 copyObject,
You can’t perform that action at this time.
0 commit comments