MCPcopy Create free account
hub / github.com/apify/impit / parseMultipart

Function parseMultipart

impit-node/test/mock.server.ts:29–55  ·  view source on GitHub ↗
(body: Buffer, boundary: string)

Source from the content-addressed store, hash-verified

27}
28
29function parseMultipart(body: Buffer, boundary: string): Record<string, string> {
30 const form: Record<string, string> = {};
31 const delimiter = Buffer.from(`--${boundary}`);
32 const separator = Buffer.from('\r\n\r\n');
33
34 let start = body.indexOf(delimiter);
35 while (start !== -1) {
36 start += delimiter.length;
37 const next = body.indexOf(delimiter, start);
38 if (next === -1) break;
39
40 const part = body.subarray(start, next);
41 const headerEnd = part.indexOf(separator);
42 if (headerEnd !== -1) {
43 const headerText = part.subarray(0, headerEnd).toString('utf8');
44 const nameMatch = headerText.match(/name="([^"]+)"/);
45 if (nameMatch) {
46 // Strip the trailing CRLF that precedes the next boundary.
47 const value = part.subarray(headerEnd + separator.length, part.length - 2).toString('utf8');
48 form[nameMatch[1]] = value;
49 }
50 }
51 start = next;
52 }
53
54 return form;
55}
56
57export async function runServer(port: number): Promise<Server> {
58 const app = express();

Callers 1

runServerFunction · 0.85

Calls 1

fromMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…