Skip to content

Instantly share code, notes, and snippets.

@joliss
Last active December 18, 2015 05:39
Show Gist options
  • Save joliss/5733886 to your computer and use it in GitHub Desktop.
Save joliss/5733886 to your computer and use it in GitHub Desktop.
// I want to pass a stream containing 'your string' into a callback.
// Here is the working streams1 code:
var through = require('through')
// Create a paused stream and buffer some data into it:
var stream = through().pause().queue('your string').end()
// Pass stream around:
callback(null, stream)
// Now that a consumer has attached, don't forget to resume the stream:
stream.resume()
// It seems that the `through` module is fundamentally streams1.
// If I omit the pause()/resume(), it doesn't magically switch
// to streams2, it just breaks (loses all its data):
var through = require('through')
var stream = through().queue('your string').end() // <-- no .pause()
callback(null, stream) // data in the stream is lost
// So I'm essentially stuck with streams1 I guess?
@joliss
Copy link
Author

joliss commented Jun 8, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment