@@ -49,14 +49,10 @@ function eos(stream, options, callback) {
49
49
50
50
callback = once ( callback ) ;
51
51
52
- const readable = options . readable ||
53
- ( options . readable !== false && isReadableNodeStream ( stream ) ) ;
54
- const writable = options . writable ||
55
- ( options . writable !== false && isWritableNodeStream ( stream ) ) ;
52
+ const readable = options . readable ?? isReadableNodeStream ( stream ) ;
53
+ const writable = options . writable ?? isWritableNodeStream ( stream ) ;
56
54
57
- if ( isNodeStream ( stream ) ) {
58
- // Do nothing...
59
- } else {
55
+ if ( ! isNodeStream ( stream ) ) {
60
56
// TODO: Webstreams.
61
57
// TODO: Throw INVALID_ARG_TYPE.
62
58
}
@@ -65,7 +61,9 @@ function eos(stream, options, callback) {
65
61
const rState = stream . _readableState ;
66
62
67
63
const onlegacyfinish = ( ) => {
68
- if ( ! stream . writable ) onfinish ( ) ;
64
+ if ( ! stream . writable ) {
65
+ onfinish ( ) ;
66
+ }
69
67
} ;
70
68
71
69
// TODO (ronag): Improve soft detection to include core modules and
@@ -83,10 +81,17 @@ function eos(stream, options, callback) {
83
81
// Stream should not be destroyed here. If it is that
84
82
// means that user space is doing something differently and
85
83
// we cannot trust willEmitClose.
86
- if ( stream . destroyed ) willEmitClose = false ;
84
+ if ( stream . destroyed ) {
85
+ willEmitClose = false ;
86
+ }
87
87
88
- if ( willEmitClose && ( ! stream . readable || readable ) ) return ;
89
- if ( ! readable || readableFinished ) callback . call ( stream ) ;
88
+ if ( willEmitClose && ( ! stream . readable || readable ) ) {
89
+ return ;
90
+ }
91
+
92
+ if ( ! readable || readableFinished ) {
93
+ callback . call ( stream ) ;
94
+ }
90
95
} ;
91
96
92
97
let readableFinished = isReadableFinished ( stream , false ) ;
@@ -95,10 +100,17 @@ function eos(stream, options, callback) {
95
100
// Stream should not be destroyed here. If it is that
96
101
// means that user space is doing something differently and
97
102
// we cannot trust willEmitClose.
98
- if ( stream . destroyed ) willEmitClose = false ;
103
+ if ( stream . destroyed ) {
104
+ willEmitClose = false ;
105
+ }
99
106
100
- if ( willEmitClose && ( ! stream . writable || writable ) ) return ;
101
- if ( ! writable || writableFinished ) callback . call ( stream ) ;
107
+ if ( willEmitClose && ( ! stream . writable || writable ) ) {
108
+ return ;
109
+ }
110
+
111
+ if ( ! writable || writableFinished ) {
112
+ callback . call ( stream ) ;
113
+ }
102
114
} ;
103
115
104
116
const onerror = ( err ) => {
@@ -139,8 +151,11 @@ function eos(stream, options, callback) {
139
151
if ( ! willEmitClose ) {
140
152
stream . on ( 'abort' , onclose ) ;
141
153
}
142
- if ( stream . req ) onrequest ( ) ;
143
- else stream . on ( 'request' , onrequest ) ;
154
+ if ( stream . req ) {
155
+ onrequest ( ) ;
156
+ } else {
157
+ stream . on ( 'request' , onrequest ) ;
158
+ }
144
159
} else if ( writable && ! wState ) { // legacy streams
145
160
stream . on ( 'end' , onlegacyfinish ) ;
146
161
stream . on ( 'close' , onlegacyfinish ) ;
@@ -153,7 +168,9 @@ function eos(stream, options, callback) {
153
168
154
169
stream . on ( 'end' , onend ) ;
155
170
stream . on ( 'finish' , onfinish ) ;
156
- if ( options . error !== false ) stream . on ( 'error' , onerror ) ;
171
+ if ( options . error !== false ) {
172
+ stream . on ( 'error' , onerror ) ;
173
+ }
157
174
stream . on ( 'close' , onclose ) ;
158
175
159
176
if ( closed ) {
0 commit comments