MCPcopy Create free account
hub / github.com/Noumena-Network/code / drainStream

Function drainStream

src/testing/ptyContractHarness.ts:189–212  ·  view source on GitHub ↗
(
    stream: ReadableStream<Uint8Array>,
    onChunk: (chunk: string) => void,
  )

Source from the content-addressed store, hash-verified

187 }
188
189 async function drainStream(
190 stream: ReadableStream<Uint8Array>,
191 onChunk: (chunk: string) => void,
192 ): Promise<string> {
193 const reader = stream.getReader()
194 const decoder = new TextDecoder()
195 let text = ''
196
197 while (true) {
198 const { done, value } = await reader.read()
199 if (done) {
200 const chunk = decoder.decode()
201 if (chunk.length > 0) {
202 text += chunk
203 onChunk(chunk)
204 }
205 return text
206 }
207
208 const chunk = decoder.decode(value, { stream: true })
209 text += chunk
210 onChunk(chunk)
211 }
212 }
213
214 function onText(chunk: string): void {
215 rawText += chunk

Callers 1

spawnPtyContractSessionFunction · 0.85

Calls 1

readMethod · 0.45

Tested by

no test coverage detected