Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

467 B
Raw Blame
export const createReadableStream = <T>(chunks: T[]) =>
  new ReadableStream({
    start(controller) {
      chunks.forEach((chunk) => controller.enqueue(chunk));

      controller.close();
    },
  });

export const readStreamChunk = async (stream: ReadableStream) => {
  const decoder = new TextDecoder();
  const chunks = [];

  // @ts-ignore
  for await (const chunk of stream) {
    chunks.push(decoder.decode(chunk, { stream: true }));
  }

  return chunks;
};