Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created October 12, 2011 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/1282775 to your computer and use it in GitHub Desktop.
Save isaacs/1282775 to your computer and use it in GitHub Desktop.
diff --git a/lib/zlib.js b/lib/zlib.js
index 43725bf..a5821e7 100644
--- a/lib/zlib.js
+++ b/lib/zlib.js
@@ -246,6 +246,8 @@ Zlib.prototype.end = function end(chunk, cb) {
return ret;
};
+var reqCache = {};
+
Zlib.prototype._process = function() {
if (this._processing || this._paused) return;
@@ -270,6 +272,7 @@ Zlib.prototype._process = function() {
var availOutBefore = this._chunkSize - this._offset;
var inOff = 0;
+
var req = this._binding.write(this._flush,
chunk, // in
inOff, // in_off
@@ -282,7 +285,12 @@ Zlib.prototype._process = function() {
req.callback = callback;
this._processing = req;
+ var reqId = req.id = Math.random();
+ reqCache[reqId] = req;
+
function callback(availInAfter, availOutAfter, buffer) {
+ reqCache[reqId] = null;
+
var have = availOutBefore - availOutAfter;
assert(have >= 0, 'have should not go down');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment