Skip to content

Web ReadableStream to Node Readable stream and vice versa for Deno

Notifications You must be signed in to change notification settings

CesiumLabs/streamconv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

StreamConv

Node.js stream to Web stream and vice versa.

Example

Web streams to node stream

import Converter from "https://deno.land/x/streamconv/mod.ts";

const res = await fetch("https://mysite.com");

if (res.body) {
    const stream = Converter.WebToReadable(res.body); // Readable stream instance
    stream.on("data", chunk => console.log(chunk.toString()));
} else {
    console.log("no stream");
}

Node stream to web stream

import Converter from "https://deno.land/x/streamconv/mod.ts";

const res = await fetch("https://mysite.com");

if (res.body) {
    const stream = Converter.WebToReadable(res.body);
    const webstream = Converter.ReadableToWeb(stream); // web ReadableStream instance
} else {
    console.log("no stream");
}