MCPcopy Index your code
hub / github.com/simstudioai/sim / readBodyWithLimit

Function readBodyWithLimit

apps/sim/connectors/utils.ts:126–149  ·  view source on GitHub ↗
(
  response: Response | SecureFetchResponse,
  maxBytes: number
)

Source from the content-addressed store, hash-verified

124 * Returns null when the cap is exceeded.
125 */
126export async function readBodyWithLimit(
127 response: Response | SecureFetchResponse,
128 maxBytes: number
129): Promise<Buffer | null> {
130 if (!response.body) {
131 const buffer = Buffer.from(await response.arrayBuffer())
132 return buffer.byteLength > maxBytes ? null : buffer
133 }
134
135 const reader = response.body.getReader()
136 const chunks: Uint8Array[] = []
137 let total = 0
138 while (true) {
139 const { done, value } = await reader.read()
140 if (done) break
141 total += value.byteLength
142 if (total > maxBytes) {
143 await reader.cancel().catch(() => {})
144 return null
145 }
146 chunks.push(value)
147 }
148 return Buffer.concat(chunks)
149}
150
151/**
152 * Marks a listed document stub as intentionally skipped — for example because it

Callers 9

utils.test.tsFile · 0.90
getFileDocumentFunction · 0.90
downloadFileContentFunction · 0.90
downloadFileContentFunction · 0.90
s3.tsFile · 0.90
downloadFileContentFunction · 0.90
downloadTextFileFunction · 0.90
zoom.tsFile · 0.90

Calls 4

cancelMethod · 0.80
concatMethod · 0.80
readMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected