Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,19 @@ function compression (options) {
var _on = res.on
var _write = res.write

var flushCB = function flushCB () {
stream.flush()
}

var endCB = function endCB () {
stream.end()
}

// flush
res.flush = function flush () {
if (stream) {
stream.flush()
// call write and pass flushCB to force synchronous behavior
stream.write('', flushCB)
}
}

Expand Down Expand Up @@ -110,9 +119,10 @@ function compression (options) {
ended = true

// write Buffer for Node.js 0.8
// call write and pass endCB to force synchronous behavior
return chunk
? stream.end(new Buffer(chunk, encoding))
: stream.end()
? stream.write(new Buffer(chunk, encoding), endCB)
: stream.write('', endCB)
}

res.on = function on (type, listener) {
Expand Down