Firstly, use `require('stream').Stream` for backwards compatibility with 
node v0.4.

Look at the stream API for the methods and properties that you'll need to 
add to your class for it to be a valid stream.
http://nodejs.org/api/stream.html

Write streams can have the pipe methods if they are also a read stream. And 
if not, you can listen to the `pipe` event and throw an error if it's 
called.

If your event emitter emits `data` events and it's all it does, there's 
some modules that make converting it into a stream easier

https://github.com/JSBizon/node-memorystream
https://github.com/dominictarr/event-stream

On Wednesday, March 14, 2012 11:59:38 AM UTC-7, Rambo wrote:
>
> I made a 'class' that connects to a stream and emits JSON objects. It 
> implements EventEmitter and emits events like 'object', 'error', etc.
> I would like to convert my class into a Readable stream because it will be 
> useful to use the pipe method. How can I do that?
>
> Is this enough?
>
> function MyClass() {}
> util.inherits(MyClass, require('stream'))
> MyClass.prototype.pause = function() {...}
> MyClass.prototype.resume = function() {...}
> ...
>
> But what if I want a writable stream, it should not have the pipe method. 
> Which is the cleanest way of implementing your own streams?
>
> Thanks.
>

-- 
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