Files
2nd/10_Wiki/Topics/Domain_Programming/Programming & Language/스트림Stream.md
T
Antigravity Agent c24165b8bc refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게
[공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류.
문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인).

- Topic_Programming → Domain_Programming (내부 구조 보존)
- Topic_Graphic → Domain_Design
- Topic_Business → Domain_Product
- Topic_General → Domain_General
- _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning),
  Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing)
- 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서)
- 빈 폴더 정리 (memory/procedures)
- 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 11:05:56 +09:00

4.2 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-스트림-stream 스트림(Stream) 10_Wiki/Topics verified self
stream
streaming
none A 0.95 applied
stream
async
io
2026-05-10 pending
language framework
typescript nodejs

스트림(Stream)

매 한 줄

"매 데이터를 chunk 단위로 점진 전달한다". 매 entire payload 를 buffer 에 fully load 하지 않고, 매 사용 가능한 시점마다 chunk 를 yield → 매 memory footprint 감소 + first-byte latency 개선. 매 modern web (Server-Sent Events · LLM token streaming · HTTP/2 push) 의 backbone.

매 핵심

매 Stream 의 종류

  • Readable: pull-based source (file read, HTTP response).
  • Writable: push-based sink (file write, response.write).
  • Duplex: read + write (TCP socket).
  • Transform: read → mutate → write (gzip, JSON.parse).

매 동작 모델

  • Chunk + backpressure: consumer slow → producer pause (highWaterMark).
  • Object mode: chunk 가 raw bytes 가 아닌 object.
  • Pipe: source.pipe(transform).pipe(sink) chain.

매 응용

  1. LLM token streaming (Claude · GPT-5 의 SSE response).
  2. Large file upload/download (Multipart, S3 multipart).
  3. Real-time analytics (Kafka consumer).

💻 패턴

Web Streams API (cross-platform)

const response = await fetch("/api/llm");
const reader = response.body!.pipeThrough(new TextDecoderStream()).getReader();
while (true) {
  const { value, done } = await reader.read();
  if (done) break;
  process.stdout.write(value);
}

Async iteration over Node stream

import { createReadStream } from "node:fs";
const stream = createReadStream("big.log", { encoding: "utf-8" });
for await (const chunk of stream) {
  console.log(`got ${chunk.length} chars`);
}

Transform stream — gzip on the fly

import { pipeline } from "node:stream/promises";
import { createReadStream, createWriteStream } from "node:fs";
import { createGzip } from "node:zlib";
await pipeline(createReadStream("input.txt"), createGzip(), createWriteStream("output.gz"));

Server-Sent Events (LLM token stream)

// Hono / Bun
import { streamSSE } from "hono/streaming";
app.get("/chat", c => streamSSE(c, async stream => {
  for await (const tok of llm.generate(prompt)) {
    await stream.writeSSE({ data: tok });
  }
}));

ReadableStream from generator

function makeStream<T>(gen: AsyncGenerator<T>) {
  return new ReadableStream<T>({
    async pull(controller) {
      const { value, done } = await gen.next();
      done ? controller.close() : controller.enqueue(value);
    }
  });
}

Backpressure handling

const writable = createWriteStream("out.bin");
function writeChunk(buf: Buffer) {
  if (!writable.write(buf)) {
    return new Promise<void>(res => writable.once("drain", res));
  }
  return Promise.resolve();
}

매 결정 기준

상황 Approach
Browser fetch streaming Web Streams API (response.body)
Node.js file/network node:stream + async iter
LLM token stream SSE or chunked transfer
Massive object pipeline object mode + Transform
Cross-runtime (Bun/Deno) Web Streams (standard)

기본값: Web Streams API + async iteration.

🔗 Graph

  • 부모: Nodejs 성능 최적화 및 디버깅
  • Adjacent: API 응답 및 에러 핸들링 아키텍처
  • 응용: Server Architecture

🤖 LLM 활용

언제: streaming chat UI · large file async processing · backpressure debug. 언제 X: small payload (<1MB) — buffering 이 simpler.

안티패턴

  • Concat all chunks before yielding: stream 의 의미 무효화.
  • Ignore backpressure: producer 가 consumer 추월 → memory blow up.
  • No error propagation in pipe: 한 stage error 가 silent.
  • Sync transform on huge object: event loop block.

🧪 검증 / 중복

  • Verified (Node.js docs · WHATWG Streams Standard).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — Stream API 패턴 정리