File tree Expand file tree Collapse file tree 4 files changed +38
-25
lines changed Expand file tree Collapse file tree 4 files changed +38
-25
lines changed Original file line number Diff line number Diff line change 24
24
25
25
'use strict' ;
26
26
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
-
31
27
// When using FSReqCallback, make sure to create the object only *after* all
32
28
// parameter validation has happened, so that the objects are not kept in memory
33
29
// in case they are created but never used due to an exception.
@@ -79,6 +75,10 @@ const { FSReqCallback, statValues } = binding;
79
75
const { toPathIfFileURL } = require ( 'internal/url' ) ;
80
76
const internalUtil = require ( 'internal/util' ) ;
81
77
const {
78
+ constants : {
79
+ kIoMaxLength,
80
+ kMaxUserId,
81
+ } ,
82
82
copyObject,
83
83
Dirent,
84
84
getDirents,
@@ -121,8 +121,6 @@ const {
121
121
validateInteger,
122
122
validateInt32
123
123
} = require ( 'internal/validators' ) ;
124
- // 2 ** 32 - 1
125
- const kMaxUserId = 4294967295 ;
126
124
127
125
let truncateWarn = true ;
128
126
let fs ;
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
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
3
const kWriteFileMaxChunkSize = 2 ** 14 ;
11
4
12
- // 2 ** 32 - 1
13
- const kMaxUserId = 4294967295 ;
14
-
15
5
const {
16
6
Error,
17
7
MathMax,
@@ -44,6 +34,12 @@ const {
44
34
const { isArrayBufferView } = require ( 'internal/util/types' ) ;
45
35
const { rimrafPromises } = require ( 'internal/fs/rimraf' ) ;
46
36
const {
37
+ constants : {
38
+ kIoMaxLength,
39
+ kMaxUserId,
40
+ kReadFileBufferLength,
41
+ kReadFileUnknownBufferLength,
42
+ } ,
47
43
copyObject,
48
44
getDirents,
49
45
getOptions,
Original file line number Diff line number Diff line change 4
4
MathMin,
5
5
} = primordials ;
6
6
7
+ const {
8
+ constants : {
9
+ kReadFileBufferLength,
10
+ kReadFileUnknownBufferLength,
11
+ }
12
+ } = require ( 'internal/fs/utils' ) ;
13
+
7
14
const { Buffer } = require ( 'buffer' ) ;
8
15
9
16
const { FSReqCallback, close, read } = internalBinding ( 'fs' ) ;
@@ -18,15 +25,6 @@ const lazyDOMException = hideStackFrames((message, name) => {
18
25
return new DOMException ( message , name ) ;
19
26
} ) ;
20
27
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
-
30
28
function readFileAfterRead ( err , bytesRead ) {
31
29
const context = this . context ;
32
30
Original file line number Diff line number Diff line change @@ -113,6 +113,21 @@ const kMaximumCopyMode = COPYFILE_EXCL |
113
113
COPYFILE_FICLONE |
114
114
COPYFILE_FICLONE_FORCE ;
115
115
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 kMaxUserId = 2 ** 32 - 1 ;
130
+
116
131
const isWindows = process . platform === 'win32' ;
117
132
118
133
let fs ;
@@ -815,6 +830,12 @@ const validatePosition = hideStackFrames((position, name) => {
815
830
} ) ;
816
831
817
832
module . exports = {
833
+ constants : {
834
+ kIoMaxLength,
835
+ kMaxUserId,
836
+ kReadFileBufferLength,
837
+ kReadFileUnknownBufferLength,
838
+ } ,
818
839
assertEncoding,
819
840
BigIntStats, // for testing
820
841
copyObject,
You can’t perform that action at this time.
0 commit comments