Hi Dhruv,

I created a BufferedStream class that can do what you need (
http://github.com/mjijackson/bufferedstream, thanks Martin for the link!).
I use it mainly for creating mocks of streams in tests. You can instantiate
a new BufferedStream with either a string, Buffer, or even another stream
as its "source". It will let you do something like:

var myStream = new BufferedStream(aBuffer);

myStream.on('data', function (chunk) {
  console.log(chunk.toString());
});

myStream.on('end', function () {
  console.log('done');
});

Another common use case is for generating streams of data that serve
long-running HTTP requests. In these cases you can just instantiate a new
BufferedStream without any source at all and write to it just like any
other stream.

var myStream = new BufferedStream;

myStream.write(aBuffer);
myStream.write('a string');
myStream.end();


--
Michael Jackson
@mjackson



On Wed, Dec 12, 2012 at 5:36 PM, dhruvbird <[email protected]> wrote:

> Hello,
>
> Is there a module that creates a ReadableStream given a Buffer, or
> something like if I write to the stream, it emits the 'data' event every
> time someone writes to it.
>
> I found 2 modules, both of which seem unrelated:
>
> https://github.com/dodo/node-bufferstream
> https://github.com/bnoordhuis/node-buffertools
>
> Regards,
> -Dhruv.
>
>  --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to