@@ -7,14 +7,14 @@ const tmpdir = require('../common/tmpdir');
77const file = path . join ( tmpdir . path , 'read_stream_filehandle_test.txt' ) ;
88const input = 'hello world' ;
99
10- let output = '' ;
1110tmpdir . refresh ( ) ;
1211fs . writeFileSync ( file , input ) ;
1312
14- fs . promises . open ( file , 'r' ) . then ( common . mustCall ( ( handle ) => {
13+ fs . promises . open ( file , 'r' ) . then ( ( handle ) => {
1514 handle . on ( 'close' , common . mustCall ( ) ) ;
1615 const stream = fs . createReadStream ( null , { fd : handle } ) ;
1716
17+ let output = '' ;
1818 stream . on ( 'data' , common . mustCallAtLeast ( ( data ) => {
1919 output += data ;
2020 } ) ) ;
@@ -24,42 +24,60 @@ fs.promises.open(file, 'r').then(common.mustCall((handle) => {
2424 } ) ) ;
2525
2626 stream . on ( 'close' , common . mustCall ( ) ) ;
27- } ) ) ;
27+ } ) . then ( common . mustCall ( ) ) ;
2828
29- fs . promises . open ( file , 'r' ) . then ( common . mustCall ( ( handle ) => {
29+ fs . promises . open ( file , 'r' ) . then ( ( handle ) => {
3030 handle . on ( 'close' , common . mustCall ( ) ) ;
3131 const stream = fs . createReadStream ( null , { fd : handle } ) ;
3232 stream . on ( 'data' , common . mustNotCall ( ) ) ;
3333 stream . on ( 'close' , common . mustCall ( ) ) ;
3434
35- handle . close ( ) ;
36- } ) ) ;
35+ return handle . close ( ) ;
36+ } ) . then ( common . mustCall ( ) ) ;
3737
38- fs . promises . open ( file , 'r' ) . then ( common . mustCall ( ( handle ) => {
38+ fs . promises . open ( file , 'r' ) . then ( ( handle ) => {
3939 handle . on ( 'close' , common . mustCall ( ) ) ;
4040 const stream = fs . createReadStream ( null , { fd : handle } ) ;
4141 stream . on ( 'close' , common . mustCall ( ) ) ;
4242
4343 stream . on ( 'data' , common . mustCall ( ( ) => {
4444 handle . close ( ) ;
4545 } ) ) ;
46- } ) ) ;
46+ } ) . then ( common . mustCall ( ) ) ;
4747
48- fs . promises . open ( file , 'r' ) . then ( common . mustCall ( ( handle ) => {
48+ fs . promises . open ( file , 'r' ) . then ( ( handle ) => {
4949 handle . on ( 'close' , common . mustCall ( ) ) ;
5050 const stream = fs . createReadStream ( null , { fd : handle } ) ;
5151 stream . on ( 'close' , common . mustCall ( ) ) ;
5252
5353 stream . close ( ) ;
54- } ) ) ;
54+ } ) . then ( common . mustCall ( ) ) ;
5555
56- fs . promises . open ( file , 'r' ) . then ( common . mustCall ( ( handle ) => {
56+ fs . promises . open ( file , 'r' ) . then ( ( handle ) => {
5757 assert . throws ( ( ) => {
5858 fs . createReadStream ( null , { fd : handle , fs } ) ;
5959 } , {
6060 code : 'ERR_METHOD_NOT_IMPLEMENTED' ,
6161 name : 'Error' ,
6262 message : 'The FileHandle with fs method is not implemented'
6363 } ) ;
64- handle . close ( ) ;
65- } ) ) ;
64+ return handle . close ( ) ;
65+ } ) . then ( common . mustCall ( ) ) ;
66+
67+ fs . promises . open ( file , 'r' ) . then ( ( handle ) => {
68+ const { read : originalReadFunction } = handle ;
69+ handle . read = common . mustCallAtLeast ( function read ( ) {
70+ return Reflect . apply ( originalReadFunction , this , arguments ) ;
71+ } ) ;
72+
73+ const stream = fs . createReadStream ( null , { fd : handle } ) ;
74+
75+ let output = '' ;
76+ stream . on ( 'data' , common . mustCallAtLeast ( ( data ) => {
77+ output += data ;
78+ } ) ) ;
79+
80+ stream . on ( 'end' , common . mustCall ( ( ) => {
81+ assert . strictEqual ( output , input ) ;
82+ } ) ) ;
83+ } ) . then ( common . mustCall ( ) ) ;
0 commit comments