MCPcopy Create free account
hub / github.com/Effect-TS/effect / filePayload

Function filePayload

packages/effect/benchmark/http/multipart.ts:14–32  ·  view source on GitHub ↗
(fileSize: number, chunkSize: number)

Source from the content-addressed store, hash-verified

12const encoder = new TextEncoder()
13
14const filePayload = (fileSize: number, chunkSize: number): Array<Uint8Array> => {
15 const head = encoder.encode(
16 `--${boundary}\r\ncontent-disposition: form-data; name="file"; filename="file.bin"\r\ncontent-type: application/octet-stream\r\n\r\n`
17 )
18 const body = new Uint8Array(fileSize)
19 for (let i = 0; i < fileSize; i++) {
20 body[i] = i % 251
21 }
22 const tail = encoder.encode(`\r\n--${boundary}--\r\n`)
23 const payload = new Uint8Array(head.length + body.length + tail.length)
24 payload.set(head, 0)
25 payload.set(body, head.length)
26 payload.set(tail, head.length + body.length)
27 const chunks: Array<Uint8Array> = []
28 for (let i = 0; i < payload.length; i += chunkSize) {
29 chunks.push(payload.subarray(i, i + chunkSize))
30 }
31 return chunks
32}
33
34const fieldsPayload = (fieldCount: number): Array<Uint8Array> => {
35 let out = ""

Callers 1

multipart.tsFile · 0.85

Calls 2

pushMethod · 0.80
setMethod · 0.65

Tested by

no test coverage detected