MCPcopy
hub / github.com/simstudioai/sim / downloadFromS3

Function downloadFromS3

apps/sim/lib/uploads/providers/s3/client.ts:191–219  ·  view source on GitHub ↗
(
  key: string,
  customConfig?: S3Config,
  maxBytes?: number
)

Source from the content-addressed store, hash-verified

189): Promise<Buffer>
190
191export async function downloadFromS3(
192 key: string,
193 customConfig?: S3Config,
194 maxBytes?: number
195): Promise<Buffer> {
196 const config = customConfig || { bucket: S3_CONFIG.bucket, region: S3_CONFIG.region }
197
198 const command = new GetObjectCommand({
199 Bucket: config.bucket,
200 Key: key,
201 })
202
203 const response = await getS3Client().send(command)
204 if (maxBytes !== undefined && response.ContentLength !== undefined) {
205 try {
206 assertKnownSizeWithinLimit(response.ContentLength, maxBytes, 'storage download')
207 } catch (error) {
208 const body = response.Body as { destroy?: (error?: Error) => void } | undefined
209 body?.destroy?.(error instanceof Error ? error : undefined)
210 throw error
211 }
212 }
213
214 const stream = response.Body as NodeJS.ReadableStream
215 return readNodeStreamToBufferWithLimit(stream, {
216 maxBytes: maxBytes ?? Number.MAX_SAFE_INTEGER,
217 label: 'storage download',
218 })
219}
220
221/**
222 * Stream an object out of S3 without buffering it. The caller MUST fully consume or

Callers 2

client.test.tsFile · 0.90
downloadFileFunction · 0.85

Calls 5

getS3ClientFunction · 0.85
sendMethod · 0.80
destroyMethod · 0.65

Tested by

no test coverage detected