-
Notifications
You must be signed in to change notification settings - Fork 633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement streams toWeb/fromWeb #2310
Comments
We have Duplex.fromWeb #2086, but yes, Readable.fromWeb/toWeb, Writable.fromWeb/toWeb, Duplex.toWeb are still missing |
import { from } from 'https://deno.land/[email protected]/node/internal/streams/readable.mjs';
const nodeReadableStreamToWebReadableStream = (
inputStream: NodeJS.ReadableStream,
): ReadableStream => {
const outputStream = new TransformStream();
const outputStreamWritableWriter = outputStream.writable.getWriter();
(async () => {
for await (const chunk of inputStream) {
outputStreamWritableWriter.write(chunk);
}
})().then(() => {
outputStreamWritableWriter.close();
}).catch((error) => {
outputStreamWritableWriter.abort(error);
});
return outputStream.readable;
};
const webReadableStreamToNodeReadableStream = (
inputStream: ReadableStream,
): NodeJS.ReadableStream => {
return from(inputStream);
}; This worked for me but it's probably not how you'd want to implement it. |
cc @crowlKats |
Closing as these are now implemented. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
I want to convert from Node.js streams to Web streams and back. Node.js has the methods
toWeb
andfromWeb
to do this.Describe the solution you'd like
Implement these functions.
Describe alternatives you've considered
I tried implementing the helper functions but got stuck because
.pipe()
didn't work. (https://gist.github.com/Industrial/f67723dcb6a2b4b576e7f06707c2ad94)The text was updated successfully, but these errors were encountered: