Kind: Type
Source: src/context.ts
Data type can be a string, ArrayBuffer, Uint8Array (buffer), or ReadableStream.
Data represents payload content accepted by the context layer. It can hold text as a string, binary content as an ArrayBuffer or Uint8Array, or streaming content as a ReadableStream.
Definition
tsstring | ArrayBuffer | ReadableStream | Uint8Array<ArrayBuffer>
Diagram
mermaidgraph LR Data[Data] --> Text[string] Data --> Buffer[ArrayBuffer] Data --> Bytes[Uint8Array] Data --> Stream[ReadableStream]
Usage
tsimport type { Data } from "./context";
function sendPayload(data: Data) {
if (typeof data === "string") {
return new TextEncoder().encode(data);
}
return data;
}
const text: Data = "Hello";
const bytes: Data = new Uint8Array([72, 105]);
const buffer: Data = bytes.buffer;
sendPayload(text);
sendPayload(bytes);
sendPayload(buffer);
AI Coding Instructions
- Accept
Datawhen an API supports text, binary buffers, or streamed payloads. - Check for
stringbefore handling binary or stream values. - Keep
Uint8Arrayviews intact when byte offsets or lengths matter. - Handle
ReadableStreamseparately from in-memory data because stream content may only be read once.
Relationships
- IMPORTS →
HonoRequest - IMPORTS →
HtmlEscapedCallbackPhase - IMPORTS →
resolveCallback
Was this page helpful?