Skip to main content
This package works with Bun, Cloudflare Workers, Node.js, Deno, Browsers
JSR Score
64%
Published
2 months ago (0.2.6)

@clapp/transporter

Client

import {
  IncomingTextStream,
  OutgoingTextStream,
} from "@clappcodes/transporter";

async function receive() {
  const stream = new IncomingTextStream("/foo");

  for await (const chunk of await stream.ready) {
    console.log("(server)", chunk);
  }
}

async function send() {
  const stream = new OutgoingTextStream("/foo");

  await stream.write("Hello from browser");
}

Server

import {
  IncomingTextStream,
  OutgoingTextStream,
} from "@clappcodes/transporter";

async function receive(request: Request) {
  const stream = new IncomingTextStream(request);

  for await (const chunk of await stream.ready) {
    console.log("(client)", chunk);
  }
}

async function send(request: Request) {
  const stream = new OutgoingTextStream(request);

  stream.write("Hello from server");
  // new Response(stream.readable)
  return stream.response();
}

// pseudo request handlers
app.put("/foo", receive);
app.get("/foo", send);

Add Package

deno add @clappcodes/transporter

Import symbol

import * as mod from "@clappcodes/transporter";

Add Package

npx jsr add @clappcodes/transporter

Import symbol

import * as mod from "@clappcodes/transporter";

Add Package

yarn dlx jsr add @clappcodes/transporter

Import symbol

import * as mod from "@clappcodes/transporter";

Add Package

pnpm dlx jsr add @clappcodes/transporter

Import symbol

import * as mod from "@clappcodes/transporter";

Add Package

bunx jsr add @clappcodes/transporter

Import symbol

import * as mod from "@clappcodes/transporter";