@@ -1707,6 +1707,7 @@ function FsReadStream(vol, path, options) {
17071707 Readable . call ( this , options ) ;
17081708
17091709 this . path = pathToFilename ( path ) ;
1710+ this . _fileHandle = options . fd && typeof options . fd !== 'number' ? options . fd : null ;
17101711 this . fd = options . fd === undefined ? null : typeof options . fd !== 'number' ? options . fd . fd : options . fd ;
17111712 this . flags = options . flags === undefined ? 'r' : options . flags ;
17121713 this . mode = options . mode === undefined ? 0o666 : options . mode ;
@@ -1840,10 +1841,17 @@ FsReadStream.prototype.close = function (cb) {
18401841 this . closed = true ;
18411842 }
18421843
1843- this . _vol . close ( this . fd , er => {
1844- if ( er ) this . emit ( 'error' , er ) ;
1845- else this . emit ( 'close' ) ;
1846- } ) ;
1844+ if ( this . _fileHandle ) {
1845+ this . _fileHandle . close ( ) . then (
1846+ ( ) => this . emit ( 'close' ) ,
1847+ er => this . emit ( 'error' , er ) ,
1848+ ) ;
1849+ } else {
1850+ this . _vol . close ( this . fd , er => {
1851+ if ( er ) this . emit ( 'error' , er ) ;
1852+ else this . emit ( 'close' ) ;
1853+ } ) ;
1854+ }
18471855
18481856 this . fd = null ;
18491857} ;
@@ -1876,6 +1884,7 @@ function FsWriteStream(vol, path, options) {
18761884 Writable . call ( this , options ) ;
18771885
18781886 this . path = pathToFilename ( path ) ;
1887+ this . _fileHandle = options . fd && typeof options . fd !== 'number' ? options . fd : null ;
18791888 this . fd = options . fd === undefined ? null : typeof options . fd !== 'number' ? options . fd . fd : options . fd ;
18801889 this . flags = options . flags === undefined ? 'w' : options . flags ;
18811890 this . mode = options . mode === undefined ? 0o666 : options . mode ;
@@ -2006,10 +2015,17 @@ FsWriteStream.prototype.close = function (cb) {
20062015 this . closed = true ;
20072016 }
20082017
2009- this . _vol . close ( this . fd , er => {
2010- if ( er ) this . emit ( 'error' , er ) ;
2011- else this . emit ( 'close' ) ;
2012- } ) ;
2018+ if ( this . _fileHandle ) {
2019+ this . _fileHandle . close ( ) . then (
2020+ ( ) => this . emit ( 'close' ) ,
2021+ er => this . emit ( 'error' , er ) ,
2022+ ) ;
2023+ } else {
2024+ this . _vol . close ( this . fd , er => {
2025+ if ( er ) this . emit ( 'error' , er ) ;
2026+ else this . emit ( 'close' ) ;
2027+ } ) ;
2028+ }
20132029
20142030 this . fd = null ;
20152031} ;
0 commit comments