summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2012-10-30 10:16:28 -0700
committerisaacs <i@izs.me>2012-10-31 16:56:30 -0700
commit07d3b21f4352e58928b6b6c2c3c0bfc59153bea9 (patch)
tree8aacd1bd040b4212d19f30efcaa35b6e1f97115b /lib
parentcfbfaaa87d4145cfc2e2e2e8f9ee3e987d52ae43 (diff)
downloadandroid-node-v8-07d3b21f4352e58928b6b6c2c3c0bfc59153bea9.tar.gz
android-node-v8-07d3b21f4352e58928b6b6c2c3c0bfc59153bea9.tar.bz2
android-node-v8-07d3b21f4352e58928b6b6c2c3c0bfc59153bea9.zip
zlib: s/clear/close/ and match other close() semantics
Diffstat (limited to 'lib')
-rw-r--r--lib/zlib.js19
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/zlib.js b/lib/zlib.js
index b0826a8f54..9b56241146 100644
--- a/lib/zlib.js
+++ b/lib/zlib.js
@@ -153,7 +153,6 @@ function zlibBuffer(engine, buffer, callback) {
var buf = Buffer.concat(buffers, nread);
buffers = [];
callback(null, buf);
- engine._clear();
}
engine.on('error', onError);
@@ -298,7 +297,9 @@ function Zlib(opts, mode) {
this._chunkSize = opts.chunkSize || exports.Z_DEFAULT_CHUNK;
this._buffer = new Buffer(this._chunkSize);
this._offset = 0;
- var self = this;
+ this._closed = false;
+
+ this.once('end', this.close);
}
util.inherits(Zlib, Stream);
@@ -356,8 +357,18 @@ Zlib.prototype.end = function end(chunk, cb) {
return ret;
};
-Zlib.prototype._clear = function() {
- return this._binding.clear();
+Zlib.prototype.close = function(callback) {
+ if (callback)
+ process.nextTick(callback);
+
+ if (this._closed)
+ return;
+
+ this._closed = true;
+
+ this._binding.close();
+
+ process.nextTick(this.emit.bind(this, 'close'));
};
Zlib.prototype._process = function() {