How can I populate a Readable stream with data from another Readable stream?
My use case is a bit strange, I have a function that reads a file from disk using fs.createReadStream and returns that stream. Now I want to create a variant to the function that loads the file over HTTP instead, but still returning a read stream so that clients can treat both functions equally.
The simplest version of what I'm trying to do is something like this,
var makeStream = function(url) {
var stream = require('stream');
var rs = new stream.Readable();
var request = http.get(url, function(result) {
// What goes here?
});
return rs;
};
What I basically want is a way to return the HTTP result stream, but because it's hidden in the callback I can't.
I feel like I'm missing something really obvious, what is it?