@@ -5,17 +5,17 @@ const common = require('../common');
5
5
// The following tests validate base functionality for the fs.promises
6
6
// FileHandle.readFile method.
7
7
8
- const fs = require ( 'fs' ) ;
8
+ const fs = require ( 'node: fs' ) ;
9
9
const {
10
10
open,
11
11
readFile,
12
12
writeFile,
13
- truncate,
14
13
} = fs . promises ;
15
- const path = require ( 'path' ) ;
14
+ const path = require ( 'node:path' ) ;
15
+ const os = require ( 'node:os' ) ;
16
16
const tmpdir = require ( '../common/tmpdir' ) ;
17
17
const tick = require ( '../common/tick' ) ;
18
- const assert = require ( 'assert' ) ;
18
+ const assert = require ( 'node: assert' ) ;
19
19
const tmpDir = tmpdir . path ;
20
20
21
21
tmpdir . refresh ( ) ;
@@ -35,6 +35,29 @@ async function validateReadFile() {
35
35
await fileHandle . close ( ) ;
36
36
}
37
37
38
+ async function validateLargeFileSupport ( ) {
39
+ const LARGE_FILE_SIZE = 3 * 1024 * 1024 * 1024 ; // 3 GiB
40
+ const FILE_PATH = path . join ( os . tmpdir ( ) , 'large-virtual-file.bin' ) ;
41
+
42
+ function createVirtualLargeFile ( ) {
43
+ return Buffer . alloc ( LARGE_FILE_SIZE , 'A' ) ;
44
+ }
45
+
46
+ const virtualFile = createVirtualLargeFile ( ) ;
47
+
48
+ await writeFile ( FILE_PATH , virtualFile ) ;
49
+
50
+ const buffer = await readFile ( FILE_PATH ) ;
51
+
52
+ assert . strictEqual (
53
+ buffer . length ,
54
+ LARGE_FILE_SIZE ,
55
+ `Expected file size to be ${ LARGE_FILE_SIZE } , but got ${ buffer . length } `
56
+ ) ;
57
+
58
+ await fs . promises . unlink ( FILE_PATH ) ;
59
+ }
60
+
38
61
async function validateReadFileProc ( ) {
39
62
// Test to make sure reading a file under the /proc directory works. Adapted
40
63
// from test-fs-read-file-sync-hostname.js.
@@ -100,32 +123,10 @@ async function doReadAndCancel() {
100
123
101
124
await fileHandle . close ( ) ;
102
125
}
103
-
104
- // Validate file size is within range for reading
105
- {
106
- // Variable taken from https://github.com/nodejs/node/blob/1377163f3351/lib/internal/fs/promises.js#L5
107
- const kIoMaxLength = 2 ** 31 - 1 ;
108
-
109
- if ( ! tmpdir . hasEnoughSpace ( kIoMaxLength ) ) {
110
- // truncate() will fail with ENOSPC if there is not enough space.
111
- common . printSkipMessage ( `Not enough space in ${ tmpDir } ` ) ;
112
- } else {
113
- const newFile = path . resolve ( tmpDir , 'dogs-running3.txt' ) ;
114
- await writeFile ( newFile , Buffer . from ( '0' ) ) ;
115
- await truncate ( newFile , kIoMaxLength + 1 ) ;
116
-
117
- const fileHandle = await open ( newFile , 'r' ) ;
118
-
119
- await assert . rejects ( fileHandle . readFile ( ) , {
120
- name : 'RangeError' ,
121
- code : 'ERR_FS_FILE_TOO_LARGE'
122
- } ) ;
123
- await fileHandle . close ( ) ;
124
- }
125
- }
126
126
}
127
127
128
128
validateReadFile ( )
129
+ . then ( validateLargeFileSupport )
129
130
. then ( validateReadFileProc )
130
131
. then ( doReadAndCancel )
131
132
. then ( common . mustCall ( ) ) ;
0 commit comments