joyent/node — pull request #2640 by ress (2012-01-30 04:06:26+00:00)
Title: Adding .destroy() method to Zlib class

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)

This pull request implements a destroy() method. I hope that's in line with the ongoing discussion about which Stream classes should implement which methods.