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