MCPcopy Index your code
hub / github.com/anomalyco/opencode / collectStream

Function collectStream

packages/core/src/process.ts:121–137  ·  view source on GitHub ↗
(stream: Stream.Stream<Uint8Array, PlatformError>, maxOutputBytes: number | undefined)

Source from the content-addressed store, hash-verified

119 : input
120
121export const collectStream = (stream: Stream.Stream<Uint8Array, PlatformError>, maxOutputBytes: number | undefined) =>
122 Stream.runFold(
123 stream,
124 () => ({ chunks: [] as Uint8Array[], bytes: 0, truncated: false }),
125 (acc, chunk) => {
126 if (maxOutputBytes === undefined) {
127 acc.chunks.push(chunk)
128 acc.bytes += chunk.length
129 return acc
130 }
131 const remaining = maxOutputBytes - acc.bytes
132 if (remaining > 0) acc.chunks.push(remaining >= chunk.length ? chunk : chunk.slice(0, remaining))
133 acc.bytes += chunk.length
134 acc.truncated = acc.truncated || acc.bytes > maxOutputBytes
135 return acc
136 },
137 ).pipe(Effect.map((x) => ({ buffer: Buffer.concat(x.chunks), truncated: x.truncated })))
138
139const layer = Layer.effect(
140 Service,

Callers 3

runFunction · 0.90
runCommandFunction · 0.85
runStreamFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected