(stream: Stream.Stream<Uint8Array, PlatformError>, maxOutputBytes: number | undefined)
| 119 | : input |
| 120 | |
| 121 | export 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 | |
| 139 | const layer = Layer.effect( |
| 140 | Service, |
no test coverage detected