INNER CODE UNIT · TypeScript
MAX_BUFFER_BYTES
tomascupr/sandstorm · clients/typescript/src/index.ts:93
const MAX_BUFFER_BYTES = 16 * 1024 * 1024;
const reader = body.getReader();
const decoder = new TextDecoder();
let buffer = "";
try {
while (true) {
const { done, value } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
if (buffer.length > MAX_BUFFER_BYTES) {
throw new Error(
`Sandstorm SSE: event exceeds ${MAX_BUFFER_BYTES} bytes without a terminator`,
);
}
let boundary = buffer.indexOf("\n\n");
while (boundary !== -1) {
const rawEvent = buffer.slice(0, boundary);
buffer = buffer.slice(boundary + 2);