> _**SDK skill · `pipe` namespace** · ~17,025 tokens · hoody-sdk v1.0.0-beta.17_ # `pipe` — Zero-storage streaming HTTP transfers ## Purpose HTTP rendezvous. Sender POST/PUTs a path; receivers GET it; bytes fan out in-memory, zero server storage. Paths exist only while pending/active. ## When to use - Endpoint-to-endpoint bytes without staging. - Fan-out (`?n=`, N ≤ 256). - Live video via `?video`. - Telemetry via `?progress`. - Browser send page `/` (file, text or pasted image; receive link + QR), no-JS form `/noscript`. ## When NOT to use Persist → `files`, HTTP client → `curl`, shell → `terminal`; no replay/queue (no storage). ## Prerequisites - All peers share kit URL, `{path}`, `n`. ## Capability URL → See `SKILL-SDK.md § Proxy URLs`. **Reaching a service you host on a container port** (any port, any namespace): - `https://{projectId}-{containerId}-http-.{node}.containers.hoody.com` — proxy speaks HTTP to `localhost:`. - `https://{projectId}-{containerId}-https-.{node}.containers.hoody.com` — proxy speaks HTTPS to `localhost:` (target needs TLS). Edge is always `https://`. No alias, firewall edit, or proxy registration needed; capability-token gates still apply. ## Common workflows Send with `client.pipe.send` (per-call request headers go in `{ headers }`). The generated `client.pipe.receive(path, options)` returns the whole body buffered in `data`; for a streaming body and the forwarded response headers, receive with `PipeStream` (Node entry of `hoody-sdk`; `const ps = PipeStream.fromClient(client, container)`), whose `ps.receive(path, { n, download, filename, wait, sha256, live, signal })` resolves once the sender starts, with `{ body, headers, status, transferId }`: `body` is a `ReadableStream` and `headers` the forwarded response headers. A non-2xx answer throws. In a browser, `PipeBrowser.receive(path, { n, live, signal })` returns `{ body, headers, status }` with no `transferId`: read it from `headers.get('X-Hoody-Pipe-Transfer-Id')`. A `live` receiver gets no transfer id (`transferId: null`, and the header lookup returns null); inspect a live stream by name with `status(path)`. ### 1. One-to-one `ps.receive` with `path` (resolves once a sender arrives; read `body` to the end); `pipe.send` same `path`. `n=1`. ### 2. Fan-out (N ≤ 256) All peers use the same `path` and the same receiver count (`n: N`). A mismatch → 400. ### 3. Download / inline per receiver `ps.receive` with `download: true` and/or `filename` → attachment; `download: false` → inline. ### 4. Watch via `?progress` Open an `EventSource` on the transfer URL with `?progress=1` for live SSE events, or open that URL in a browser for the HTML dashboard. From Node, `ps.subscribeProgress(path)` (`PipeStream`) yields the same events. `ps.receive` is a receiver, not a spectator: it takes a slot and gets the data. No receiver slot. ### 5. Video via `?video` Open the transfer URL with `?video=1` in a browser → MSE player. `ps.receive(path)` does not ask for HTML, so it gets the raw bytes. Sender: WebM / fMP4 (MPEG-TS plays in VLC/mpv, not in the browser player). ### 6. Page links a person only confirms Compose one URL with every control filled in; the person opens it and clicks (capture and file picks always need their click). Invalid values fall back to the page defaults. `` is the kit URL; `` is encoded per `/` segment. Send page `/api/v1/pipe/?name=&…`: | Param | Values | Effect | |---|---|---| | `name` | ≤1024 chars | pipe name (absent → random) | | `n` | 1–256 | receiver count | | `text` | ≤100000 chars | text to send; selects text mode | | `mode` | `file` \| `text` | form mode | | `filename` | ≤255 chars | name the receiver gets for a text or pasted image | | `autostart` | `1` | text mode with non-empty text: send on open, no click (no `name` needed: an absent one is generated, and the page still sends) | Receive page `/api/v1/pipe/?receive&…`: | Param | Values | Effect | |---|---|---| | `n` | 1–256 | receiver count, the sender's `n` | | `filename` | ≤255 chars | download name | | `autostart` | `1` | start the download on open, no click | Share page `/api/v1/pipe/?share&…` (viewers open the video page): | Param | Values | Effect | |---|---|---| | `source` | `screen` \| `camera` \| `audio` | what to capture (default `screen`) | | `audio` | `1` \| `0` | include the screen's audio | | `surface` | `monitor` \| `window` \| `browser` | kind offered first in the screen picker | | `quality` | `low` \| `medium` \| `high` | up to 480p / 720p / 1080p (default `medium`) | | `fps` | 1–60 | frame rate (default 30) | | `n` | 1–256 | viewer count | | `live` | `1` | live broadcast: starts at once, viewers join and leave at any time through `?video&live=1`; `n` does not apply | Video page `/api/v1/pipe/?video&n=&live=1&wait=` (`n` only when >1, not with `live`; `live=1` plays a live broadcast; `wait` 1-3600 s is how long the player waits for the stream; opening it receives). Progress page `/api/v1/pipe/?progress` (no params, no slot). No-JS form `/api/v1/pipe/noscript?path=&mode=file|text&wait=&sha256=1` (`wait` and `sha256` go on to its upload). In a browser, `PipeBrowser` and `PipeMedia` (from `hoody-sdk`, `fromClient(client, container)` or `{ pipeBaseUrl }`) have `getPageUrl(page, name, options)` and `openPage(page, name, options)` for `send`, `receive`, `share`, `video`, `progress`, `noscript`; options use the param names above (`autostart: true`, `audio: true|false`, `sha256: true`, `live: true`, `wait: `; `wait`/`sha256` on receive and noscript, `live`/`wait` on video). A wrong option, out-of-range value, reserved name (see Quirks), `.`/`..` segment or over-long name throws. The `noscript` link carries the name encoded as in the pipe URL in its `path` (so its form posts to the same pipe) and refuses a name with `/`. `PipeBrowser` also has `sendFile(path, File|Blob|string|ArrayBuffer, { n, filename, contentType, transfer, onProgress, onStatus, signal })` (resolves when the transfer completes, rejects with `PipeTransferError` when the transfer fails; built with `fromClient`, a refused request (non-2xx) throws the client's `ApiError` instead), `receive(path, { n, signal })` → `{ body, headers, status }`, `download(path, { n, filename })` (browser download manager) and `subscribeProgress(path)` (same events as `PipeStream`). `PipeMedia.shareAudio({ microphone, systemAudio, n })` streams audio only; listeners open `session.url` (`?video`). A share session (`shareScreen`, `shareWebcam`, `shareAudio`) uploads with its own transfer id (`?transfer=`, `session.transferId`) and follows only that transfer (`?status&transfer=` and its `done` event), so another transfer on the name never ends it. It stops the capture when its transfer ends; `session.done` rejects with `PipeTransferError` when it failed (nobody joined in 5 minutes, every viewer left, idle timeout, network, an id in use (409), or its transfer unknown to the kit for about 30 s after it was seen), and a bad `path` throws before capture starts. The recording follows the upload: once 8 MiB of it wait to be sent (no receiver reading yet, a slow network) the recorder pauses (`session.paused` is true), and it resumes when the upload is back to 4 MiB behind; a pause by `session.pause()` stays until `session.resume()`. More than 16 MiB waiting ends the share and `session.done` rejects. Embed views `pipe.send`, `pipe.share`, `pipe.receive` take the same params except `autostart`; framing the share page needs `allow="display-capture; camera; microphone; autoplay"`. ### 7. Status, waiting time and checksums `?status` is one JSON snapshot of a name, with no receiver slot: `state` (`idle`, `waiting`, `streaming`, `complete`, `failed`), `kind` (`pipe`, `ws`, `live` or null), `peers`, `transferId`, `hasSender`, `activeReceivers`, `totalReceivers`, `bytesTransferred`, `totalBytes`, `speed`, `eta`, `elapsed`, `reason`, `sha256`. `?wait=` (1-3600, default 300) sets how long one sender or receiver waits for the other side. `?sha256` (sender or any receiver) has the kit hash the stream; receivers of an ordinary (not `?live`) transfer get the transfer id in `X-Hoody-Pipe-Transfer-Id`, and `?status&transfer=` returns that transfer, for a hashed one also for up to 10 min after it ends (the kit keeps at most 1,000 receipts in all and evicts the oldest first, so a busy kit can drop one sooner). Prometheus metrics: `GET /api/v1/pipe/metrics`. Through `PipeStream` (`const ps = PipeStream.fromClient(client, container)`; `PipeBrowser` has `status` too): `ps.status(path, { transfer? })` returns the snapshot. `ps.send` also takes `transfer` (its own transfer id, 16-64 of A-Z a-z 0-9 `_` `-`; the kit uses it as the transfer id, so `ps.status(path, { transfer })` reads this transfer from admission on; an id in use → 409; `PipeBrowser.sendFile` too). `ps.send` and `ps.receive` take `wait` and `sha256`: on send the result's `sha256` promise gives the kit's digest (null when not hashed or failed); on receive `sha256: true` hashes the body while it is read and `verified` rejects with `PipeIntegrityError` (`kind` `mismatch`, `unavailable` or `incomplete`) unless it matches the kit's digest. `ps.send` returns once the kit takes the upload. Its `done` resolves only when the kit's last status line confirms the transfer (`Transfer complete.`, or `Live stream ended (peak N viewers).` for `live`); otherwise it rejects with `PipeTransferError`, whose `message` is the kit's text (`Timed out waiting for receivers.`, `All receivers disconnected before transfer completed.`, an idle timeout) or `pipe send failed: the response ended before the transfer completed`, with `status` and the status lines in `messages`. A refused send (non-2xx) throws the client's `ApiError` when `ps` was built with `fromClient`, and `PipeTransferError` with that `status` on the global-fetch transport (`{ pipeBaseUrl }`). `ps.send` `filename` goes in `Content-Disposition` as `PipeBrowser.sendFile` sends it: a non-ASCII name as RFC 5987 `filename*` plus an ASCII fallback. `ps.metrics()` returns the metrics text. ### 8. Live broadcast (`?live`) A live sender streams at once, with nobody watching; any number of viewers (256 at once) join and leave while it runs and each gets the stream from then on (no `Content-Length`, header `X-Hoody-Pipe-Live: 1`; the headers come with the viewer's first bytes). WebM joins at the next keyframe Cluster after the stream header, so players decode it; anything else joins at the next chunk. Bytes sent while nobody watches are dropped. A viewer 8 MiB or 4096 pieces behind, taking nothing for 60 s, or furthest behind when the live memory budget (64 MiB per stream, 512 MiB in all) is full is cut: its body ends with an error. A clean sender end gives each viewer up to 60 s to finish; a sender that disconnects, fails or idles 5 min cuts every viewer. Sender status: `[INFO] Live: streaming. Viewers can join at any time.`, then `[INFO] Live stream ended (peak N viewers).` or an `[ERROR]` line. `?status` shows `kind: "live"`, viewers in `activeReceivers`, `totalReceivers: null`; `?progress` events carry `live: true`. Not with `n` above 1, `sha256`, `ws` or multipart (400); a live sender on a name with an ordinary transfer, an ordinary sender on a live name, or a plain GET while `?live` viewers wait → 409 (a plain GET on a running live stream joins it). Caps: 100 live streams, 4096 viewer responses in all (each counts until it disconnects or 35 s after its body ended) → 429. `ps.send(path, source, { live: true })` and `ps.receive(path, { live: true })` (`PipeStream`); `PipeBrowser.receive(path, { live: true })`; `PipeMedia.shareScreen|shareWebcam|shareAudio({ live: true })` (WebM only; asks the recorder for a keyframe every 2 s; `session.url` carries `live`), `sendStream`/`receiveStream`/`receiveMedia` `{ live: true }`, `getPageUrl('video'|'share', name, { live: true })`. `subscribeProgress` (`PipeStream` and `PipeBrowser`) sets `live: true` on a live stream's `state` and `progress` events (false otherwise), and a live `state` event's `totalReceivers` is null. `live` with `n` above 1 or `sha256`, or a share with a non-WebM `mimeType`, throws before any request or capture. With Node's fetch the sender's request goes out with the first body chunk. A `PipeStream` live viewer under Bun is never skipped or cut for reading slowly: Bun's `fetch` reads the body ahead without backpressure, so the kit sees it keeping up and the backlog grows in the viewer's own memory instead. Under Node a slow viewer is skipped and cut as described. ## Quirks & gotchas - Available over SDK, HTTP and the `hoody pipe` CLI. - `/api/v1/pipe/{path}` ≡ bare `/{path}` for transfer paths, except a name equal to `api/v1/pipe` or starting with `api/v1/pipe/` (the prefix is stripped once, so those are reachable only under the prefix: `/api/v1/pipe/api/v1/pipe/x` is the pipe `api/v1/pipe/x`). Health is the other exception: `/api/v1/pipe/health` answers GET/HEAD/OPTIONS, and a bare `/health` returns 404; both are matched case-insensitively with one trailing `/` or `.` allowed (`/api/v1/pipe/health/` is health, `/Health` is 404). Percent-escapes in a name match regardless of hex case (`caf%c3%a9` = `caf%C3%A9`) but are not decoded (`%41` ≠ `A`). - Reserved: `/`, `/noscript`, `/help`, `/favicon.ico`, `/robots.txt` (alias-hardened). `health` and `metrics` are not pipe names either: under the prefix they are the health and metrics endpoints, and at the root they answer 404. The SDK (`PipeStream`, `PipeBrowser`, `PipeMedia`, page URLs) and the CLI refuse all of these before any request, and every SDK URL builder (`getUrl`, `getWsUrl`, `getDownloadUrl`, `getPageUrl`) throws on them, matched as the kit matches them: case-insensitive, one trailing `/` then one trailing `.` ignored, so `Metrics.`, `help/` and an empty name are refused. Runs of `/` are merged first, so `/help`, `//metrics` and `metrics//` are refused too: the kit itself serves `/help` as the pipe `//help`, but an edge that merges slashes would send it to the help page. - `n` ≤ 256; peers must agree. Caps 1000 pending + 1000 active. - The kit limits the path name (the pathname after the `/api/v1/pipe` prefix is removed, leading `/` not counted) to 1024 characters, the same cap the SDK and CLI check. Percent-encoding counts against the kit's limit, so a name with characters the URL must encode can pass the SDK and CLI check and still get 414. That is the only length limit the kit applies: there is no total-URL cap in the kit, so an extremely long URL is refused (if at all) by the HTTP server in front of it, with a differently shaped error. Control characters, backslashes and encoded slashes → 400. - A sender or receiver waits for the other side for its own `?wait` (default 5 min, at most 1 h); an active transfer idle for 5 min is ended. - Dangerous sender MIME (HTML/SVG/JS) → `text/plain`; `nosniff` forced. - Forwarded sender→receiver headers: `Content-Type` (sanitized — dangerous MIME → `text/plain`), `Content-Length` (only for a non-multipart body, and only when the value is 1–19 plain digits; multipart transfers are sent without it), `X-Piping`, `X-Hoody-Pipe` (each ≤8 KiB, CRLF-stripped). `Content-Disposition` is rebuilt per-receiver from sender metadata + receiver `?download`/`?filename` params. - `?download` enum (SDK-validated): `"true"`/`"false"`/`"yes"`/`"no"`/`"1"`/`"0"` (attach / inline). The kit is more permissive — bare `?download` (no value) and any non-`false`/`no`/`0` string are treated as truthy. `?filename=` implies attach, sanitised (255 chars, RFC 5987), unless the same receiver also sent an explicit `download=false`/`no`/`0`, which suppresses Content-Disposition entirely. - `?video` HTML player only on `Accept: text/html`; no receiver slot. A valid `?wait` on the player URL is used by each of its receives; an invalid one is ignored. It plays each stream to its end, even a short file that arrives all at once, then waits on the same path: the next stream sent there replaces it. Audio-only WebM (Opus/Vorbis) plays as audio; with `?n=N` the players may be tabs of one browser. Without `live` it never skips content (a stream that fell behind stays behind; it reads at most 45 s ahead); with `live` (`?video&live=1`), a player that falls behind may jump to the newest buffered media. Playback stopped 1.5 s with media buffered ahead moves on to it. - `?progress` no receiver slot. Caps: 50/path, 500 groups, 30 min TTL. - `?receive` and `?share` serve pages only on `Accept: text/html` (a browser); any other client gets the data as a plain receiver, like `?video`. With several page params on one URL a browser gets `?progress`, then `?video`, then `?share`, then `?receive`; `=0`/`false`/`no` turns one off. - `?receive` page: shows the name and whether a sender waits (from `?progress`, no slot). On the person's click — or by itself with `autostart=1` — the browser's download manager receives `?download` (plus `n`, `filename`, and the page's own `wait` and `sha256`), so any size goes to disk without passing through the page. Progress and the result are only in the browser's downloads list: the page cannot see the download, so after Receive it stays `Receiving in your browser` and never reports success. Its only outcome is `Failed` with the kit's error text when the download frame gets one (`Timed out waiting for sender.` after 5 min or the page's `wait`, an `n` mismatch, a taken slot); `?progress` state snapshots fill an info line labelled "Status for this name" (all its senders and receivers, not this download: no sender yet / sender waiting for receivers / transfer running; "Status unavailable, retrying…" while the stream is down) and never set an outcome. Cancel frees the slot while waiting (a started download goes on in the browser's downloads); Receive again after a failure retries. Pre-fill: `n` (invalid → 1, max 256), `filename` (sanitized like `?filename`), `autostart=1` (only `1`/`true`/`yes`/bare), `wait` (1-3600 s; invalid → dropped), `sha256` (forwarded only; the page shows no checksum). - `?share` page: shares the screen (with its audio if ticked), the camera with the microphone, or the microphone only, live to the `?video` player. - Start sharing asks the browser for the capture (the person's click), then sends one WebM stream to the name and shows a viewer link (Copy + QR) to `?video` (plus `&n=`). - Without Live, the stream starts when all `n` viewers have opened the link; until then the page shows `Waiting for viewers… x of n connected`. With Live (the Live box or `live=1`), it is a `?live` broadcast that starts at once and viewers join and leave at any time. The page shows viewers, elapsed time and bytes sent (from `?progress`, no slot). - Stop, or the browser's own stop-sharing control, ends the stream; Start sharing again shares on the same name and players still open on the link play it. - Without Live, it ends with a message when nobody (or not all `n`) opened the link within 5 min, or all viewers left. In either mode it ends with a message when the name is busy, the kit refused the share (its error text), or the connection cannot keep up. - It needs a browser that can stream an upload (Chromium-based) over HTTPS with HTTP/2 or HTTP/3; any other browser gets a message instead of a start. It stores nothing in the browser. - Pre-fill: `source=screen|camera|audio`, `audio=1` (screen audio), `surface=monitor|window|browser` (offered first in the picker), `quality=low|medium|high` (up to 480p/720p/1080p), `fps` (1–60, default 30), `n` (1–256), `live=1` (Live). Invalid values fall back to the defaults; capture still needs the click on Start sharing. - `/` (also `/api/v1/pipe/`) is the send page. - It sends one file, a typed or pasted text, or a pasted image (sent as a file). - It fills in a random name that the person can edit, plus `n`. Send/Cancel uses one POST to `/api/v1/pipe/`: each `/`-separated part of the name is encoded, so `?`, `#` and `%` stay in the name, and leading `/` are kept. A name with a `.` or `..` part (also `%2e`) is refused before sending, as in the SDK. - The file name, or `filename` for a text or pasted image, goes in `Content-Disposition`. A typed or URL-given file name is kept when a file is picked or pasted. - It reports Delivered only when the POST response ends with `[INFO] Transfer complete.`; any other ending is shown as Failed. Each `[INFO] A receiver disconnected.` after `[INFO] Streaming to …` is a receiver that did not get everything: `Delivered to 1 of 2 receivers (1 disconnected).` - It shows the connected receivers and the state from `?progress` (no slot). It shows a receive link (Copy + QR) to `?receive` (plus `&n=`). - Cancel frees the name. The page stores nothing in the browser and sends a nonce CSP with `connect-src 'self'`. - Pre-fill: `name` (≤1024; absent → random), `n` (1–256, invalid → 1), `text` (≤100000, selects text mode), `mode=file|text`, `filename` (≤255), `autostart=1` (text mode with a text only; never for a file; a refused name shows the reason instead). Over-long values are cut without splitting a character. - To hand a person a ready send link, build `/api/v1/pipe/?name=&text=` (add `&autostart=1` to send it on open, `&filename=`, `&n=N`). For a file, give `?name=`: they pick the file and click Send. - WebSocket relay: `GET /{name}?ws` with an upgrade pairs exactly two peers. Messages pass both ways with their type and boundaries kept, at most 1 MiB each. The first peer's messages are held (4096 / 2 MiB) until the second arrives (`?wait`, default 300 s, then close `4408`). A slow reader more than 2 MiB behind closes the pair with `1013`. Close codes 1000-1003, 1007-1014 and 3000-4999 are forwarded; a drop arrives as `1001`. The first peer's subprotocol binds the pair. A name holds either a transfer or a pair, never both (409 both ways); `?status` shows `kind: "ws"`, `peers`. SDK: create `ps` with `PipeStream.fromClient(client, container)`, then `ps.connect(name, { wait, protocols, signal })` → `{ readable, writable, closed, close }`, one chunk = one message; a refusal is a `PipeWsError` with `.status`; `ps.forwardTcp({ transport: 'ws', path, listen|connect })`. - To hand a person a ready receive link, build `/api/v1/pipe/?receive&autostart=1&filename=` (add `&n=N` for N receivers); they open it and the file lands in their downloads when the sender sends. A share link is `/api/v1/pipe/?share&source=screen|camera|audio` (capture still needs their click on Start); viewers open `/api/v1/pipe/?video`. - `Service-Worker: script` → 400. - `Content-Range` on POST/PUT → 400. - Multipart: the **first file part** wins. Non-file parts before it are drained; the transfer ends when that part ends; anything after it is ignored, and the body stops being read once the transfer finishes. A body cut off or dropped before that part ends fails the transfer (sender `[ERROR] Transfer failed`, waiting receivers 500). With no file part, the first `input_text` field is delivered instead (as `text/plain; charset=utf-8`, no disposition); a text field over 1 MiB fails the transfer. The 30 s deadline covers only the wait for the first file or `input_text` part; after that the 5 min idle limit applies. ## Common errors - 400 — active / sender attached / `n` mismatch / slots full / `n`>256 / reserved / forbidden chars / `Service-Worker` / `Content-Range`. - 405 — method. HEAD works only on the reserved pages, `/api/v1/pipe/health`, `/api/v1/pipe/metrics` and `?status`; transfer paths accept GET, POST, PUT and OPTIONS. On a reserved page or health, the 405 carries `Allow: GET, HEAD, OPTIONS` (POST/PUT to a reserved page are 400, to health 405). - 408 — a waiting receiver whose own `?wait` (default 5 min) passes before the pipe is established gets it; the others keep waiting. The body names the missing side: `[ERROR] Timed out waiting for sender.` when no sender is attached, `[ERROR] Timed out waiting for receivers.` when the sender is attached but some of the `n` receivers never came. The sender has already had its `200` response; it learns of the timeout only from `[ERROR] Timed out waiting for receivers.` in its streamed status body. - 409 — `?ws` on a name with two peers already, with a transfer, or with a different subprotocol than the first peer's; a sender or receiver on a name that holds a WebSocket pair; a sender whose `?transfer=` is still in use (`[ERROR] Transfer id already in use.`). - 426 — `?ws` without a WebSocket upgrade. - 414 — path name (leading `/` not counted) over 1024 characters. - 429 — pending-transfer cap, spectator caps, and, for receivers, the active-transfer cap. A sender that hits the active-transfer cap has already had its `200`; it gets `[ERROR] Server at maximum active transfer capacity.` in its status body. ## Related namespaces `files` persist · `curl` HTTP client · `tunnel` long-lived bidi · `terminal`/`exec` shell. ## Examples Each example has HTTP, CLI and SDK forms. The CLI forms use the `hoody pipe` subcommands. Set `P`, `C`, `N` (project id, container id, server name) from `containers.get` first, then `KIT="https://${P}-${C}-pipe-1.${N}.containers.hoody.com"`. Pipe paths are reservations: receivers and senders rendezvous on the same path. Pick a unique path (e.g. `transfer-$(openssl rand -hex 4)`) per transfer — once it's claimed by a sender or receiver, the same path can't host another transfer until the first one finishes or the 5-min idle TTL evicts it. ### 1. One-to-one transfer — receiver waits, sender pushes bytes **Goal:** stream a payload from one endpoint to another with zero staging. Receiver opens the GET first; the connection blocks until the sender POSTs to the same path. **Step 1 — start the receiver in the background.** It blocks until the sender connects. ```typescript import { PipeStream } from 'hoody-sdk'; // `container` is the container record (from containers.get) the pipe kit runs in. const ps = PipeStream.fromClient(client, container); const pathName = `transfer-${crypto.randomUUID().slice(0, 8)}`; // ps.receive resolves once the sender arrives; read its body stream to the end. const recvPromise = ps.receive(pathName) .then(async (r) => new Uint8Array(await new Response(r.body).arrayBuffer())); ``` **Step 2 — send the bytes.** Sender's response is a streamed `[INFO]` log: ``` [INFO] Waiting for 1 receiver(s) to connect... [INFO] 1 receiver(s) already connected. [INFO] Streaming to 1 receiver(s)... [INFO] Upload complete. [INFO] Transfer complete. ``` ```typescript // `data` accepts a string, Blob, ArrayBuffer, Uint8Array, FormData or ReadableStream. await client.pipe.send(pathName, new Blob(['hello pipe!'], { type: 'text/plain' })); const received = await recvPromise; console.log(new TextDecoder().decode(received)); // → hello pipe! ``` ### 2. Fan-out 1-to-3 — one sender, three receivers **Goal:** broadcast the same bytes to three endpoints in lockstep. All four parties (3 receivers + 1 sender) must agree on `n=3`; mismatch → 400. **Step 1 — open three receivers.** Each must pass `?n=3`. ```typescript const pathName = `broadcast-${crypto.randomUUID().slice(0, 8)}`; // ps = PipeStream.fromClient(client, container), as in example 1 const receivers = [1, 2, 3].map(() => ps.receive(pathName, { n: 3 }) .then(async (r) => new Uint8Array(await new Response(r.body).arrayBuffer())) ); ``` **Step 2 — send once; all three receivers get an identical copy.** Lockstep fan-out: the slowest receiver paces the transfer. ```typescript await client.pipe.send(pathName, new Blob(['fan-out-payload'], { type: 'text/plain' }), { n: 3 }); const all = await Promise.all(receivers); // all three Uint8Arrays are byte-identical ``` ### 3. Force a download with a custom filename **Goal:** make the browser save the response to disk with a specific name, regardless of what (or whether) the sender provided a `Content-Disposition`. `?filename=` implies `?download` and overrides any sender-supplied filename, unless the same receiver passes `?download=0` (which drops Content-Disposition entirely). **Response header:** `content-disposition: attachment; filename="report.bin"`. ```typescript const pathName = `dl-${crypto.randomUUID().slice(0, 8)}`; // ps = PipeStream.fromClient(client, container), as in example 1 const recv = ps.receive(pathName, { download: true, filename: 'report.bin' }) .then(async (r) => ({ headers: r.headers, bytes: new Uint8Array(await new Response(r.body).arrayBuffer()) })); await client.pipe.send(pathName, new Blob(['BINARYPAYLOAD'], { type: 'application/octet-stream' })); const r = await recv; console.log(r.headers.get('content-disposition')); // → attachment; filename="report.bin" // r.bytes holds the payload; in a browser, PipeBrowser.download(path, { filename }) hands it to the download manager ``` ### 4. Force inline display, overriding a sender's `attachment` **Goal:** the sender (e.g. a legacy script) marks every payload as `Content-Disposition: attachment; filename="leaked.txt"`, but you want to render it inline in your app. `?download=0` strips Content-Disposition entirely on the receiver side — per receiver, not globally. **Result:** sender sent `Content-Disposition: attachment; filename="leaked.txt"`; receiver got `content-type: text/plain` only — no Content-Disposition. ```typescript const pathName = `inline-${crypto.randomUUID().slice(0, 8)}`; // ps = PipeStream.fromClient(client, container), as in example 1. // Open the receiver BEFORE starting the sender (a GET after the transfer starts a new rendezvous). const recv = ps.receive(pathName, { download: false }) .then(async (r) => ({ headers: r.headers, text: await new Response(r.body).text() })); await client.pipe.send(pathName, new Blob(['inline body'], { type: 'text/plain' }), { headers: { 'Content-Disposition': 'attachment; filename="leaked.txt"' }, }); const r = await recv; console.log(r.headers.get('content-disposition')); // → null console.log(r.text); // → inline body ``` ### 5. Watch a transfer with `?progress` (SSE) **Goal:** monitor live state + bytes/sec from a third process, without consuming a receiver slot. `?progress=1` with `Accept: text/event-stream` returns SSE events; the spectator never blocks the transfer. **SSE stream** for a 50 KB payload: ``` event: state data: {"state":"idle",...} event: state data: {"state":"waiting","hasSender":true,"activeReceivers":1,...} event: state data: {"state":"streaming",...} event: progress data: {"bytesTransferred":50000,"totalBytes":50000,...} event: done data: {"state":"complete","bytesTransferred":50000,"avgSpeed":7142857} ``` Only `done` says how a transfer ended. A failed one sends `{"state":"failed",…,"reason":"Sender disconnected"}`; `state` events carry only `idle`, `waiting` and `streaming`. A spectator that connects within 30 s after a transfer ends gets `204` and no events. ```typescript // Browser/Node: use EventSource with the kit URL directly const kitUrl = `https://${P}-${C}-pipe-1.${N}.containers.hoody.com`; // P, C, N from containers.get const pathName = `watched-${crypto.randomUUID().slice(0, 8)}`; // the sender uses this same name const url = `${kitUrl}/api/v1/pipe/${pathName}?progress=1`; const es = new EventSource(url, { withCredentials: false }); es.addEventListener('state', e => console.log('state', JSON.parse((e as MessageEvent).data))); es.addEventListener('progress', e => console.log('progress', JSON.parse((e as MessageEvent).data))); es.addEventListener('done', e => { console.log('done', (e as MessageEvent).data); es.close(); }); ``` ### 6. Embed an HTML transfer dashboard **Goal:** give a non-technical user a live dashboard view of an in-flight transfer. Same `?progress=1` endpoint, but `Accept: text/html` returns a self-contained HTML page (CSP nonces, EventSource client baked in). Pop it in an `