Thanks to visit codestin.com
Credit goes to github.com

Skip to content

pliashkou/capnwebtest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cap'n Web ReadableStream Examples

This directory contains working examples demonstrating ReadableStream support in Cap'n Web.

Features Demonstrated

  • ✅ Automatic stream conversion (no manual helper functions needed!)
  • ✅ Number streams
  • ✅ Text chunk streams
  • ✅ Real-time data streams with timing
  • ✅ Binary data (Uint8Array) streams
  • ✅ Stream transformation with TransformStream
  • ✅ Manual stream processing

Setup

  1. Install dependencies:

    npm install
  2. Link to your local Cap'n Web build:

    npm link /Users/me/work/capnweb

Running the Examples

  1. Start the server in one terminal:

    node server.js
  2. Run the client in another terminal:

    node client.js

What You'll See

The client will demonstrate 6 different streaming scenarios:

  1. Number Stream: Stream a sequence of numbers
  2. Text Stream: Stream text data in chunks
  3. Real-time Stream: Simulated real-time data with delays
  4. Binary Stream: Stream Uint8Array binary data
  5. Manual Processing: Process stream chunks with custom logic
  6. Transform Stream: Use TransformStream to modify data in-flight

Key Points

On the Server (server.js)

class StreamingAPI extends RpcTarget {
  getNumberStream(count) {
    return new ReadableStream({
      pull(controller) {
        // Just return a normal ReadableStream!
        if (index < count) {
          controller.enqueue(index++);
        } else {
          controller.close();
        }
      }
    });
  }
}

On the Client (client.js)

// Stream is automatically converted - no helper functions needed!
const stream = await api.getNumberStream(5);

// Use it like any ReadableStream
const reader = stream.getReader();
const { value, done } = await reader.read();

Architecture

  • Server: Node.js HTTP + WebSocket server using Cap'n Web
  • Client: Node.js client using WebSocket connection
  • Protocol: Cap'n Web RPC with automatic stream serialization
  • Transport: WebSocket (persistent connection) or HTTP Batch (single request)

Notes

  • Streams are passed by reference and operations happen via RPC
  • The automatic conversion means you work with real ReadableStream/WritableStream objects
  • No need to learn special APIs - just use standard Web Streams API!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published