joyent/node — Issue #2639: Zlib class doesn't have .destroy() method
Author: ress
Created: 2012-01-30 04:03:17+00:00
State: open

The Zlib class in zlib.js implements a readable/writeable stream interface, but doesn't have a .destroy() method.

If the zlib classes are used in a pipe and the source emits the close event, destroy() is called on the Zlib object, causing an exception that can only be handled through the global exception handler.

Example:

zlib = require("zlib")
fs = require("fs")

gunzip = zlib.createGunzip()
rs = fs.createReadStream("/dev/zero")
rs.pipe(gunzip);

setTimeout(function() { rs.destroy(); }, 2000);

Exception:

stream.js:98
dest.destroy();
^
TypeError: Object # has no method 'destroy'
at [object Object].onclose (stream.js:98:10)
at [object Object].emit (events.js:88:20)
at Object.oncomplete (fs.js:1167:12)

I've attached a pull-request that fixes the problem for me.