substack/node-browserify — pull request #646 by parshap (2014-02-10 21:56:24+00:00)
Title: Convert to streams2 readable streams using through2()

## Summary
This patch converts all through streams created via `through()` to be streams2 streams using `through2()`. I ran into an issue because I expected the stream returned by `bundle()` to be a streams2 semantics and auto-buffer data until I start consuming it.

## Use Case
```javascript
var fs = require("fs");
var browserify = require("browserify");
var output = require("stream-stream")();

output.write(fs.createReadStream("static.js", { encoding: "utf8" });
output.write(browserify("client.js").bundle());
output.end();
output.pipe(fs.createWriteStream("bundle.js"));
```

This was broken because the bundle stream emits its data immediately before the *stream-stream* is ready to read from it. I am interested in hearing if there is a better approach I should be using to concatenate static js to my browserify bundle.

*Note*: This is broken nondeterministically, only when `static.js` is sufficiently large.

## Details
Tests passed as-is except for `test/standalone_events.js`. This is because the test is expecting a `close` event and it seems like streams2 readable streams do not emit one by default nor do they propagate close events from piped streams. I changed this test to note expect a `close` event.

Many tests use `through()` and I did not change those - I moved *through* to *devDependencies*.

## Things to Review

* Usage of `objectMode` in the right places
* Does anything rely on streams1 semantics (e.g., "auto flowing")? This is kind of an backwards-**incompatible** API change. I added calls to `stream.resume()` to automatically start flowing where it made sense (e.g., when there is a callback given).
* Should a `close` event be emitted?