This directory contains working examples demonstrating ReadableStream support in Cap'n Web.
- ✅ 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
-
Install dependencies:
npm install
-
Link to your local Cap'n Web build:
npm link /Users/me/work/capnweb
-
Start the server in one terminal:
node server.js
-
Run the client in another terminal:
node client.js
The client will demonstrate 6 different streaming scenarios:
- Number Stream: Stream a sequence of numbers
- Text Stream: Stream text data in chunks
- Real-time Stream: Simulated real-time data with delays
- Binary Stream: Stream Uint8Array binary data
- Manual Processing: Process stream chunks with custom logic
- Transform Stream: Use TransformStream to modify data in-flight
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();
}
}
});
}
}// 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();- 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)
- 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!