The proper way of implementing stream wrapper? #45069
Unanswered
Antonius-S
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all, I want to create "wrapper" (proxy, re-translator) of a Readable stream that would be Readable stream as well. Something like IncomingMessage that wraps Socket. I want it to have some data processing but for the beginning this is just a 1:1 copier. I also want the wrapper to be as slim as possible - just to do what I need with minimal code. So I'm not asking how to do this but how to do this in proper, recommended way.
I'm on Node 12.
That's what I came to so far:
And the usage is like
The reason I can't do reading in 'ReadableWrapper._read' is that source stream could be not ready at the time the method is called so its 'read' will return null thus finishing the wrapper stream. And though docs say
they say nothing what to do if data is not available from the resource
I also want the class to handle both flowing and paused mode so I can't use 'data' event.
So the questions:
Beta Was this translation helpful? Give feedback.
All reactions