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

Function buildBody

apps/sim/lib/core/utils/multipart.test.ts:14–26  ·  view source on GitHub ↗
(parts: Part[], boundary = BOUNDARY)

Source from the content-addressed store, hash-verified

12const BOUNDARY = '----testboundary1234'
13
14function buildBody(parts: Part[], boundary = BOUNDARY): Buffer {
15 const segments: Buffer[] = []
16 for (const part of parts) {
17 let header = `--${boundary}\r\nContent-Disposition: form-data; name="${part.name}"`
18 if ('filename' in part) {
19 header += `; filename="${part.filename}"\r\nContent-Type: ${part.contentType ?? 'text/csv'}`
20 }
21 header += '\r\n\r\n'
22 segments.push(Buffer.from(header, 'utf8'), Buffer.from(part.value, 'utf8'), Buffer.from('\r\n'))
23 }
24 segments.push(Buffer.from(`--${boundary}--\r\n`, 'utf8'))
25 return Buffer.concat(segments)
26}
27
28function toWebStream(body: Buffer, chunkSize?: number): ReadableStream<Uint8Array> {
29 return new ReadableStream<Uint8Array>({

Callers 1

makeRequestFunction · 0.70

Calls 2

concatMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected