diff --git a/lib/protocol/stream.js b/lib/protocol/stream.js index 441b1e6..5d65ecd 100644 --- a/lib/protocol/stream.js +++ b/lib/protocol/stream.js @@ -274,6 +274,16 @@ Stream.prototype._writeUpstream = function _writeUpstream(frame) { return moreNeeded; }; +var inflateStatusToName = { + "0": "Z_OK", + "1": "Z_STREAM_END", + "2": "Z_SYNC_FLUSH", + "-1": "ERRNO", + "-2": "STREAM_ERROR", + "-3": "DATA_ERROR", + "-4": "MEM_ERROR" +}; + // The `_receive` method (= `upstream._receive`) gets called when there's an incoming frame. Stream.prototype._receive = function _receive(frame, ready) { // * If it's a DATA frame, then push the payload into the output buffer on the other side. @@ -296,6 +306,14 @@ Stream.prototype._receive = function _receive(frame, ready) { } var data = frame.data; this.pakoInf.push(data, frame.END_STREAM); + + if (this.pakoInf.err < 0) { + var statusName = inflateStatusToName[this.pakoInf.err]; + var inflateError = new Error('Inflate frame failed with status ' + statusName); + this._log.error(inflateError, inflateError.message); + this.reset(inflateError); + this.emit('error', inflateError); + } } else {