File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -949,20 +949,23 @@ WriteStream.prototype.destroy = function (cb) {
949949 var self = this ;
950950 this . writeable = false ;
951951
952- fs . close ( self . fd , function ( err ) {
953- if ( err ) {
954- if ( cb ) {
955- cb ( err ) ;
952+ function close ( ) {
953+ fs . close ( self . fd , function ( err ) {
954+ if ( err ) {
955+ if ( cb ) { cb ( err ) ; }
956+ self . emit ( 'error' , err ) ;
957+ return ;
956958 }
957959
958- self . emit ( 'error' , err ) ;
959- return ;
960- }
960+ if ( cb ) { cb ( null ) ; }
961+ self . emit ( 'close' ) ;
962+ } ) ;
963+ }
961964
962- if ( cb ) {
963- cb ( null ) ;
964- }
965- self . emit ( 'close' ) ;
966- } ) ;
965+ if ( this . fd ) {
966+ close ( ) ;
967+ } else {
968+ this . addListener ( 'open' , close ) ;
969+ }
967970} ;
968971
Original file line number Diff line number Diff line change 1+ common = require ( "../common" ) ;
2+ assert = common . assert
3+
4+ var path = require ( 'path' ) ,
5+ fs = require ( 'fs' ) ;
6+
7+ var file = path . join ( common . fixturesDir , "write.txt" ) ;
8+
9+ ( function ( ) {
10+ var stream = fs . createWriteStream ( file ) ,
11+ _fs_close = fs . close ;
12+
13+ fs . close = function ( fd ) {
14+ assert . ok ( fd , "fs.close must not be called without an undefined fd." )
15+ fs . close = _fs_close ;
16+ }
17+ stream . destroy ( ) ;
18+ } ) ( ) ;
19+
You can’t perform that action at this time.
0 commit comments