Last active
December 18, 2015 05:39
-
-
Save joliss/5733886 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Twitter discussion at https://twitter.com/jo_liss/status/343207516299198464.