var Stream = require('stream').Stream,
  util = require('util'),
  spawn = require('child_process').spawn;

var GZipStream = function() {
  this.readable = true;
  this.writable = true;

  this._gzipper = spawn('gzip');
  this._gzipper.stdout.on('data', this.emit.bind(this, 'data'));
  this._gzipper.on('exit', this.emit.bind(this, 'end'));
};
util.inherits(GZipStream, Stream);
GZipStream.prototype.write = function(data) {
  if(this._gzipper.stdin.writable) {
    this._gzipper.stdin.write(data);
  }
};
GZipStream.prototype.end = function(data) {
  this.readable = false;
  this.writable = false;

  this._gzipper.stdin.end();
  this._gzipper = null;
};

module.exports = GZipStream;

@@ -137,29 +137,71 @@
 %7B%0A  
-this.readable = true;
+// readable stream%0A  this.readable = true;%0A  // writable stream
 %0A  t
@@ -255,16 +255,45 @@
 gzip');%0A
+  // emit data at some point%0A
   this._
@@ -349,16 +349,44 @@
 ata'));%0A
+  // emit end at some point%0A
   this._
@@ -441,42 +441,116 @@
 %0A%7D;%0A
-util.inherits(GZipStream, Stream);
+%0A// this is a custom stream object%0Autil.inherits(GZipStream, Stream);%0A%0A// implement write, process some data
 %0AGZi
@@ -672,16 +672,34 @@
 ;%0A  %7D%0A%7D;
+%0A%0A// implement end
 %0AGZipStr
@@ -735,16 +735,42 @@
 data) %7B%0A
+  // shut down processing%0A
   this.r
@@ -808,24 +808,38 @@
 e = false;%0A%0A
+  // clean up%0A
   this._gzip

comment gzipper