@@ -12,6 +12,7 @@ const {
1212let eos ;
1313
1414const { once } = require ( 'internal/util' ) ;
15+ const destroyImpl = require ( 'internal/streams/destroy' ) ;
1516const {
1617 ERR_INVALID_ARG_TYPE ,
1718 ERR_INVALID_RETURN_VALUE ,
@@ -28,14 +29,6 @@ function isRequest(stream) {
2829 return stream && stream . setHeader && typeof stream . abort === 'function' ;
2930}
3031
31- function destroyStream ( stream , err ) {
32- // request.destroy just do .end - .abort is what we want
33- if ( isRequest ( stream ) ) return stream . abort ( ) ;
34- if ( isRequest ( stream . req ) ) return stream . req . abort ( ) ;
35- if ( typeof stream . destroy === 'function' ) return stream . destroy ( err ) ;
36- if ( typeof stream . close === 'function' ) return stream . close ( ) ;
37- }
38-
3932function destroyer ( stream , reading , writing , final , callback ) {
4033 callback = once ( callback ) ;
4134 let destroyed = false ;
@@ -46,15 +39,15 @@ function destroyer(stream, reading, writing, final, callback) {
4639 destroyed = true ;
4740 const readable = stream . readable || isRequest ( stream ) ;
4841 if ( err || ! final || ! readable ) {
49- destroyStream ( stream , err ) ;
42+ destroyImpl . destroyer ( stream , err ) ;
5043 }
5144 callback ( err ) ;
5245 } ) ;
5346
5447 return ( err ) => {
5548 if ( destroyed ) return ;
5649 destroyed = true ;
57- destroyStream ( stream , err ) ;
50+ destroyImpl . destroyer ( stream , err ) ;
5851 callback ( err || new ERR_STREAM_DESTROYED ( 'pipe' ) ) ;
5952 } ;
6053}
0 commit comments