AGENT SKILL

stream-to-buffer-patterns

暂无简介

License 许可
Apache-2.0
最近更新
2026-11-14
Stars
★ 13
Forks
2

03 SKILL.md 正文

/stream-to-buffer-patterns

When to Use

  • Collect stdout/stderr from child_process into a string safely
  • Read HTTP response body stream into buffer with size cap
  • Buffer tool output before parsing (JSON, YAML, CSV)
  • Enforce max response size to prevent agent OOM on large downloads

Do NOT use for

  • Large binary files > 50MB (stream directly to disk instead)
  • Real-time line-by-line processing (use readline interface instead)

get-stream (with size limit)

import getStream from 'get-stream'
import { spawn }  from 'child_process'

async function runAndCapture(cmd: string, args: string[]): Promise<string> {
  const child = spawn(cmd, args, { stdio: ['ignore', 'pipe', 'pipe'] })

  // Cap output at 5MB to prevent OOM
  const [stdout, stderr] = await Promise.all([
    getStream(child.stdout!, { maxBuffer: 5 * 1024 * 1024 }),
    getStream(child.stderr!, { maxBuffer: 1 * 1024 * 1024 }),
  ])

  await new Promise((res, rej) => {
    child.on('close', code => code === 0 ? res(null) : rej(new Error(`exit ${code}: ${stderr}`)))
  })

  return stdout
}

get-stream.buffer (binary)

import { buffer as getBuffer } from 'get-stream'

async function downloadToBuffer(readableStream: NodeJS.ReadableStream): Promise<Buffer> {
  return getBuffer(readableStream, { maxBuffer: 10 * 1024 * 1024 })
  // throws MaxBufferError if > 10MB
}

DIY buffer collector (no dependency)

function streamToString(
  stream:    NodeJS.ReadableStream,
  maxBytes = 5 * 1024 * 1024
): Promise<string> {
  return new Promise((resolve, reject) => {
    const chunks: Buffer[] = []
    let total = 0

    stream.on('data', (chunk: Buffer) => {
      total += chunk.length
      if (total > maxBytes) {
        stream.destroy()
        reject(new Error(`[stream] max size exceeded: ${total} > ${maxBytes}`))
        return
      }
      chunks.push(chunk)
    })
    stream.on('end',   () => resolve(Buffer.concat(chunks).toString('utf8')))
    stream.on('error', reject)
  })
}

Handle encoding correctly

// UTF-8 string output
const text = await getStream(stream, { encoding: 'utf8' })

// Binary (no encoding — returns Buffer via getStream.buffer)
const buf = await getBuffer(stream)

// JSON output with parse
const json = JSON.parse(await getStream(stream, { maxBuffer: 1_048_576 }))

Anti-Fake-Pass Checklist

❌ No maxBuffer → getStream collects unlimited bytes → OOM on large output
❌ MaxBufferError not caught → unhandled rejection kills process
❌ stream.resume() not called if stream is paused → getStream hangs forever
❌ Binary stream with encoding:'utf8' → corrupts multi-byte chars at chunk boundaries
❌ child.stdout null when stdio:'ignore' → must use 'pipe' for stdout capture
❌ Promise not awaiting child close → resolve fires before process exits

04 同仓库更多 Skills

Horonomos-laps
Horonomos-laps/Yana-AI

openai--sentry--sentry

Use when the user asks to inspect Sentry issues or events, summarize recent production errors, or pull basic Sentry health data via the Sentry API; perform read-only queries with the bundled script and require `SENTRY_AUTH_TOKEN`.

★ 13
Horonomos-laps
Horonomos-laps/Yana-AI

ito-basket-compare

Compare Itô prediction-market baskets against a user's knowledge base, portfolio notes, financial context, watchlist, or research thesis. Use for read-only basket comparison and gap analysis without investment advice or live trading.

★ 13
Horonomos-laps
Horonomos-laps/Yana-AI

implementing-network-traffic-baselining

Build network traffic baselines from NetFlow/IPFIX data using Python pandas for statistical analysis, z-score anomaly detection, and hourly/daily traffic pattern profiling

★ 13
Horonomos-laps
Horonomos-laps/Yana-AI

detecting-evasion-techniques-in-endpoint-logs

Detects defense evasion techniques used by adversaries in endpoint logs including log tampering, timestomping, process injection, and security tool disabling. Use when investigating suspicious endpoint behavior, building detection rules for evasion tactics, or conducting threat hunting for stealthy adversary activity. Activates for requests involving evasion detection, defense evasion analysis, log tampering detection, or MITRE ATT&CK TA0005.

★ 13
Horonomos-laps
Horonomos-laps/Yana-AI

implementing-microsegmentation-with-guardicore

Implementing microsegmentation using Akamai Guardicore Segmentation to map application dependencies, create granular network policies, visualize east-west traffic flows, and enforce least-privilege communication between workloads across data centers and cloud.

★ 13
Horonomos-laps
Horonomos-laps/Yana-AI

ramdisk-tmpfs-patterns

暂无简介

★ 13