MCPcopy Create free account
hub / github.com/cloudflare/computer / drain

Function drain

packages/computer/src/backends/worker-javascript/frames.ts:40–52  ·  view source on GitHub ↗
(controller: TransformStreamDefaultController<RuntimeFrame>, final: boolean)

Source from the content-addressed store, hash-verified

38 const decoder = new TextDecoder();
39 let buffer = "";
40 const drain = (controller: TransformStreamDefaultController<RuntimeFrame>, final: boolean) => {
41 let nl = buffer.indexOf("\n");
42 while (nl !== -1) {
43 const line = buffer.slice(0, nl);
44 buffer = buffer.slice(nl + 1);
45 if (line.length > 0) controller.enqueue(parseRuntimeFrame(line));
46 nl = buffer.indexOf("\n");
47 }
48 if (final && buffer.length > 0) {
49 controller.enqueue(parseRuntimeFrame(buffer));
50 buffer = "";
51 }
52 };
53 return source.pipeThrough(
54 new TransformStream<Uint8Array, RuntimeFrame>({
55 transform(chunk, controller) {

Callers 2

transformFunction · 0.70
flushFunction · 0.70

Calls 1

parseRuntimeFrameFunction · 0.85

Tested by

no test coverage detected