@stacksjs/bun-router 0.1.15 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -100,10 +100,23 @@ export declare function compressResponse(response: Response, request: Request, o
100
100
  * the prefix, which is what makes a small answer distinguishable from the
101
101
  * beginning of a large one.
102
102
  */
103
- export declare function peekBody(source: ReadableStream<Uint8Array>, limit: number): Promise<{
104
- stream: ReadableStream<Uint8Array>;
103
+ export interface PeekedBody {
104
+ /**
105
+ * What to send.
106
+ *
107
+ * Bytes when the body ended inside the prefix, a stream when it did not.
108
+ * The distinction is the whole point: a body that ended was never a stream,
109
+ * it was a small answer that arrived whole, and rebuilding it as a stream
110
+ * asks Bun for a controller, a start microtask and a drain per response.
111
+ * Measured on a route returning seventeen bytes of JSON, that machinery was
112
+ * roughly three times the cost of answering the request.
113
+ */
114
+ body: ReadableStream<Uint8Array> | Uint8Array;
105
115
  size: number;
106
116
  ended: boolean;
107
- }>;
117
+ }
118
+ /** A stream again, for the branch that has to pipe what it peeked. */
119
+ export declare function peekedStream(peeked: PeekedBody): ReadableStream<Uint8Array>;
120
+ export declare function peekBody(source: ReadableStream<Uint8Array>, limit: number): Promise<PeekedBody>;
108
121
  /** Add to `Vary` without dropping what is already there. */
109
122
  export declare function appendVary(headers: Headers, value: string): void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/bun-router",
3
3
  "type": "module",
4
- "version": "0.1.15",
4
+ "version": "0.1.16",
5
5
  "description": "A fast, type-safe router for Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.com>",
7
7
  "license": "MIT",