streamWithCap
@forge/monorepo / backend/src / streamWithCap
Function: streamWithCap()
streamWithCap(
bytes,maxBytes):AsyncIterable<Uint8Array<ArrayBufferLike>>
Defined in: backend/src/files/index.ts:112
AC-2's second half, and the one that holds.
Wraps a byte stream so it stops at the cap rather than reading to the end and then complaining. The difference is the whole point: reading a hostile 1 GB body into memory and then returning an error is a denial of service that happens to report itself politely.
safefetch.py in ShareFlow exists for the same reason, and says it plainly: "the callers parse whole
documents in memory, so an unbounded download is a denial-of-service vector on a container capped at
600 MB."
Parameters
bytes
AsyncIterable<Uint8Array<ArrayBufferLike>>
maxBytes
number
Returns
AsyncIterable<Uint8Array<ArrayBufferLike>>