Skip to content

Commit 2440598

Browse files
fix(response.write): handle optional arguments
1 parent 4653825 commit 2440598

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ function compression (options) {
8080
return false
8181
}
8282

83+
if (!cb && typeof encoding === 'function') {
84+
cb = encoding
85+
encoding = undefined
86+
}
87+
8388
if (!this._header) {
8489
this._implicitHeader()
8590
}
@@ -94,6 +99,11 @@ function compression (options) {
9499
return false
95100
}
96101

102+
if (!cb && typeof encoding === 'function') {
103+
cb = encoding
104+
encoding = undefined
105+
}
106+
97107
if (!this._header) {
98108
// estimate the length
99109
if (!this.getHeader('Content-Length')) {
@@ -113,7 +123,7 @@ function compression (options) {
113123
// write Buffer for Node.js 0.8
114124
return chunk
115125
? stream.end(toBuffer(chunk, encoding), encoding, cb)
116-
: stream.end()
126+
: stream.end(cb)
117127
}
118128

119129
res.on = function on (type, listener) {

0 commit comments

Comments
 (0)