Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

zlib: emit "close" if Z_STREAM_END occurs. #3747

Closed
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+7 −3
Split
View
@@ -346,7 +346,6 @@ Zlib.prototype.end = function end(chunk, cb) {
var self = this;
this._ending = true;
var ret = this.write(chunk, function() {
- self.emit('end');
if (cb) cb();
});
this._ended = true;
@@ -392,7 +391,7 @@ Zlib.prototype._process = function() {
req.callback = callback;
this._processing = req;
- function callback(availInAfter, availOutAfter, buffer) {
+ function callback(err, availInAfter, availOutAfter, buffer) {
if (self._hadError) return;
var have = availOutBefore - availOutAfter;
@@ -438,6 +437,10 @@ Zlib.prototype._process = function() {
self._processing = false;
if (cb) cb();
self._process();
+
+ if (err == binding.Z_STREAM_END) {
+ self.emit('end');
+ }
}
};
View
@@ -211,7 +211,8 @@ class ZCtx : public ObjectWrap {
// call the write() cb
assert(ctx->handle_->Get(callback_sym)->IsFunction() &&
"Invalid callback");
- Local<Value> args[2] = { avail_in, avail_out };
+ Local<Value> args[3] = { Local<Value>::New(Number::New(ctx->err_)),
+ avail_in, avail_out };
MakeCallback(ctx->handle_, callback_sym, ARRAY_SIZE(args), args);
ctx->Unref();