@@ -13,7 +13,11 @@ const tmpdir = require('../common/tmpdir');
13
13
const assert = require ( 'assert' ) ;
14
14
const tmpDir = tmpdir . path ;
15
15
16
- tmpdir . refresh ( ) ;
16
+ async function read ( fileHandle , buffer , offset , length , position ) {
17
+ return useConf ?
18
+ fileHandle . read ( { buffer, offset, length, position } ) :
19
+ fileHandle . read ( buffer , offset , length , position ) ;
20
+ }
17
21
18
22
async function validateRead ( ) {
19
23
const filePath = path . resolve ( tmpDir , 'tmp-read-file.txt' ) ;
@@ -23,7 +27,7 @@ async function validateRead() {
23
27
const fd = fs . openSync ( filePath , 'w+' ) ;
24
28
fs . writeSync ( fd , buffer , 0 , buffer . length ) ;
25
29
fs . closeSync ( fd ) ;
26
- const readAsyncHandle = await fileHandle . read ( Buffer . alloc ( 11 ) , 0 , 11 , 0 ) ;
30
+ const readAsyncHandle = await read ( fileHandle , Buffer . alloc ( 11 ) , 0 , 11 , 0 ) ;
27
31
assert . deepStrictEqual ( buffer . length , readAsyncHandle . bytesRead ) ;
28
32
assert . deepStrictEqual ( buffer , readAsyncHandle . buffer ) ;
29
33
@@ -38,7 +42,7 @@ async function validateEmptyRead() {
38
42
const fd = fs . openSync ( filePath , 'w+' ) ;
39
43
fs . writeSync ( fd , buffer , 0 , buffer . length ) ;
40
44
fs . closeSync ( fd ) ;
41
- const readAsyncHandle = await fileHandle . read ( Buffer . alloc ( 11 ) , 0 , 11 , 0 ) ;
45
+ const readAsyncHandle = await read ( fileHandle , Buffer . alloc ( 11 ) , 0 , 11 , 0 ) ;
42
46
assert . deepStrictEqual ( buffer . length , readAsyncHandle . bytesRead ) ;
43
47
44
48
await fileHandle . close ( ) ;
@@ -51,12 +55,21 @@ async function validateLargeRead() {
51
55
const filePath = fixtures . path ( 'x.txt' ) ;
52
56
const fileHandle = await open ( filePath , 'r' ) ;
53
57
const pos = 0xffffffff + 1 ; // max-uint32 + 1
54
- const readHandle = await fileHandle . read ( Buffer . alloc ( 1 ) , 0 , 1 , pos ) ;
58
+ const readHandle = await read ( fileHandle , Buffer . alloc ( 1 ) , 0 , 1 , pos ) ;
55
59
56
60
assert . strictEqual ( readHandle . bytesRead , 0 ) ;
57
61
}
58
62
59
- validateRead ( )
60
- . then ( validateEmptyRead )
61
- . then ( validateLargeRead )
62
- . then ( common . mustCall ( ) ) ;
63
+ let useConf = false ;
64
+
65
+ ( async function ( ) {
66
+ for ( const value of [ false , true ] ) {
67
+ tmpdir . refresh ( ) ;
68
+ useConf = value ;
69
+
70
+ await validateRead ( )
71
+ . then ( validateEmptyRead )
72
+ . then ( validateLargeRead )
73
+ . then ( common . mustCall ( ) ) ;
74
+ }
75
+ } ) ;
0 commit comments