Skip to content

Data

reference
1 min readUpdated

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

ts
string | ArrayBuffer | ReadableStream | Uint8Array<ArrayBuffer>

Diagram

mermaid
graph LR
  Data[Data] --> Text[string]
  Data --> Buffer[ArrayBuffer]
  Data --> Bytes[Uint8Array]
  Data --> Stream[ReadableStream]

Usage

ts
import 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 Data when an API supports text, binary buffers, or streamed payloads.
  • Check for string before handling binary or stream values.
  • Keep Uint8Array views intact when byte offsets or lengths matter.
  • Handle ReadableStream separately from in-memory data because stream content may only be read once.

Relationships

  • IMPORTS → HonoRequest
  • IMPORTS → HtmlEscapedCallbackPhase
  • IMPORTS → resolveCallback

Was this page helpful?

Download as PDF
Data — Hono (narrator proof)