'use strict';

var Readable = require('stream').Readable;

function GeneratorStream(source) {
	if (!source.next) throw new TypeError('source must be an iterator');

	Readable.call(this, {objectMode: true});
	this._source = source;
}
GeneratorStream.prototype = Object.create(Readable.prototype, {constructor: {value: GeneratorStream}});

GeneratorStream.prototype._read = function(size) {
	try {
		// TODO This implementation does not buffer aggressively enough, and
		// the target stream typically does not either
		do {
			var r = this._source.next();

			if (r.done) {
				this.push(null);
				break;
			}
		} while (this.push(r.value));
	} catch (e) {
		this.emit('error', e);
	}
};

module.exports = GeneratorStream;

@@ -8,19 +8,21 @@
 rict';%0A%0A
-var
+const
  Readabl
@@ -397,141 +397,64 @@
 %7B%0A%09%09
-// TODO This implementation does not buffer aggressively enough, and%0A%09%09// the target stream typically does not either%0A%09%09do
+var chunk, buf=%5B%5D, sz=0;%0A%0A%09%09while (sz %3C 4096)
  %7B%0A%09%09%09
-var r
+chunk
  = t
@@ -477,74 +477,105 @@
 ();%0A
-%0A
 %09%09%09if (
-r
+chunk
 .done) 
-%7B%0A%09%09%09%09this.push(null);%0A%09%09%09%09break
+break;%0A%0A%09%09%09buf.push(chunk.value);%0A%09%09%09sz += chunk.value.length
 ;%0A%09%09
-%09
 %7D
+%0A
 %0A%09%09
-%7D while (
+if (sz) 
 this
@@ -584,16 +584,55 @@
 ush(
-r.value)
+buf.join(''));%0A%09%09if (chunk.done) this.push(null
 );%0A%09

Add buffering to GeneratorStream