Skip to main content
Glama
stream.ts1.01 kB
import { AxiosResponse } from "axios"; // Highly reusable stream utilities export type StreamLike = { on: (event: string, listener: (...args: unknown[]) => void) => void; setEncoding?: (encoding: string) => void; }; export const isValidStream = (value: unknown): value is StreamLike => value !== null && typeof value === "object" && typeof (value as Record<string, unknown>).on === "function"; export const readStreamBody = async (res: AxiosResponse): Promise<string> => { const data = res.data as unknown; if (isValidStream(data)) { return await new Promise<string>((resolve) => { let s = ""; data.setEncoding?.("utf8"); data.on("data", (...args: unknown[]) => { const c = args[0]; s += Buffer.isBuffer(c) ? c.toString() : String(c); }); data.on("end", () => resolve(s)); data.on("error", () => resolve("")); }); } return typeof res.data === "string" ? res.data : res.data == null ? "" : String(res.data); };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ExpertVagabond/universal-blockchain'

If you have feedback or need assistance with the MCP directory API, please join our Discord server