D
Deno

help

How can I create a linked [ReadableStream,WritableStream] pair?

Ddantheman3/8/2023
Hi, I have a function A which accepts a WritableStream and another function B which accepts a ReadableStream. How can I plug them into each other so that the writes from function A will be given to function B? In NodeJS this could be accomplished with an NPM package like https://github.com/indutny/stream-pair.
ABTAndreu Botella (they/them)3/8/2023
const identityTransform = new TransformStream();
a(identityTransform.writable);
b(identityTransform.readable);
const identityTransform = new TransformStream();
a(identityTransform.writable);
b(identityTransform.readable);
Ddantheman3/8/2023
hah, that's brilliant ok works great for duplex too
function makeSocketPair() {
const sideA = new TransformStream<Uint8Array>();
const sideB = new TransformStream<Uint8Array>();
return {
left: { readable: sideA.readable, writable: sideB.writable },
right: { readable: sideB.readable, writable: sideA.writable },
};
}
function makeSocketPair() {
const sideA = new TransformStream<Uint8Array>();
const sideB = new TransformStream<Uint8Array>();
return {
left: { readable: sideA.readable, writable: sideB.writable },
right: { readable: sideB.readable, writable: sideA.writable },
};
}
thank you!

Looking for more? Join the community!