@@ -13,7 +13,11 @@ const tmpdir = require('../common/tmpdir');
1313const assert = require ( 'assert' ) ;
1414const tmpDir = tmpdir . path ;
1515
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+ }
1721
1822async function validateRead ( ) {
1923 const filePath = path . resolve ( tmpDir , 'tmp-read-file.txt' ) ;
@@ -23,7 +27,7 @@ async function validateRead() {
2327 const fd = fs . openSync ( filePath , 'w+' ) ;
2428 fs . writeSync ( fd , buffer , 0 , buffer . length ) ;
2529 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 ) ;
2731 assert . deepStrictEqual ( buffer . length , readAsyncHandle . bytesRead ) ;
2832 assert . deepStrictEqual ( buffer , readAsyncHandle . buffer ) ;
2933
@@ -38,7 +42,7 @@ async function validateEmptyRead() {
3842 const fd = fs . openSync ( filePath , 'w+' ) ;
3943 fs . writeSync ( fd , buffer , 0 , buffer . length ) ;
4044 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 ) ;
4246 assert . deepStrictEqual ( buffer . length , readAsyncHandle . bytesRead ) ;
4347
4448 await fileHandle . close ( ) ;
@@ -51,12 +55,21 @@ async function validateLargeRead() {
5155 const filePath = fixtures . path ( 'x.txt' ) ;
5256 const fileHandle = await open ( filePath , 'r' ) ;
5357 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 ) ;
5559
5660 assert . strictEqual ( readHandle . bytesRead , 0 ) ;
5761}
5862
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