@@ -5,17 +5,17 @@ const common = require('../common');
55// The following tests validate base functionality for the fs.promises
66// FileHandle.readFile method.
77
8- const fs = require ( 'fs' ) ;
8+ const fs = require ( 'node: fs' ) ;
99const {
1010 open,
1111 readFile,
1212 writeFile,
13- truncate,
1413} = fs . promises ;
15- const path = require ( 'path' ) ;
14+ const path = require ( 'node:path' ) ;
15+ const os = require ( 'node:os' ) ;
1616const tmpdir = require ( '../common/tmpdir' ) ;
1717const tick = require ( '../common/tick' ) ;
18- const assert = require ( 'assert' ) ;
18+ const assert = require ( 'node: assert' ) ;
1919const tmpDir = tmpdir . path ;
2020
2121tmpdir . refresh ( ) ;
@@ -35,6 +35,29 @@ async function validateReadFile() {
3535 await fileHandle . close ( ) ;
3636}
3737
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+
3861async function validateReadFileProc ( ) {
3962 // Test to make sure reading a file under the /proc directory works. Adapted
4063 // from test-fs-read-file-sync-hostname.js.
@@ -100,32 +123,10 @@ async function doReadAndCancel() {
100123
101124 await fileHandle . close ( ) ;
102125 }
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- }
126126}
127127
128128validateReadFile ( )
129+ . then ( validateLargeFileSupport )
129130 . then ( validateReadFileProc )
130131 . then ( doReadAndCancel )
131132 . then ( common . mustCall ( ) ) ;
0 commit comments