Search code examples
javascriptnode.jsstreamdenonode-streams

Is there an equivalent way to achieve Node's readable.unshift method using Deno's ReadableStream?


I want to port some code written for Node to Deno, but I ran into an issue with Deno's ReadableStream lacking an unshift method, like what Node has with readable.unshift.

I know there is Node Compatibility Mode in Deno, but the Deno ReadableStream I have to use is coming from this Deno API so I cannot substitute it for the Node Compatibility Mode API.

Is there a way to emulate the behavior of Node's unshift method using a Deno ReadableStream, so data can be put back onto the Deno stream?


Solution

  • I was able to work around the issue by storing the buffer that would need to be written using the missing unshift method, then combining it with the buffer from the next read of the stream, which functions similarly to what unshift does without directly involving the stream itself.