{"library":"mixpart","title":"mixpart","description":"The `mixpart` library is a high-performance streaming parser for `multipart/mixed` messages in Node.js, designed for optimal memory efficiency and robust error handling. It currently ships as version `0.0.5` and is primarily intended as a private workspace package within a monorepo, implying a stable but internally-focused release cadence rather than frequent public updates. Its key differentiators include true streaming processing where each message payload is exposed as a `ReadableStream`, preventing full buffering of entire parts, and zero memory buffering for message payloads. It also features built-in memory safety configurations to guard against unbounded memory growth from malformed data, optimized search algorithms using Node.js `Buffer.indexOf` for fast boundary detection, and proper ISO-8859-1 header decoding per HTTP standards. The package also provides comprehensive TypeScript support.","language":"javascript","status":"maintenance","last_verified":"Thu Apr 23","install":{"commands":["npm install mixpart"],"cli":null},"imports":["import { parseMultipartStream } from 'mixpart'","import { MultipartMessage } from 'mixpart'","import { ParserOptions } from 'mixpart'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { parseMultipartStream, MultipartMessage } from \"mixpart\";\n\n// Simulate a fetch call to a multipart/mixed endpoint\nasync function simulateMultipartFetch() {\n  // In a real application, replace this with an actual fetch call\n  // For demonstration, we'll create a dummy ReadableStream\n  const dummyStream = new ReadableStream({\n    start(controller) {\n      controller.enqueue(new TextEncoder().encode(\n        '--BOUNDARY\\r\\n'\n      ));\n      controller.enqueue(new TextEncoder().encode(\n        'Content-Type: text/plain\\r\\n'\n      ));\n      controller.enqueue(new TextEncoder().encode(\n        'X-Custom-Header: hello\\r\\n'\n      ));\n      controller.enqueue(new TextEncoder().encode(\n        '\\r\\n'\n      ));\n      controller.enqueue(new TextEncoder().encode(\n        'This is part one.\\r\\n'\n      ));\n      controller.enqueue(new TextEncoder().encode(\n        '--BOUNDARY\\r\\n'\n      ));\n      controller.enqueue(new TextEncoder().encode(\n        'Content-Type: application/json\\r\\n'\n      ));\n      controller.enqueue(new TextEncoder().encode(\n        '\\r\\n'\n      ));\n      controller.enqueue(new TextEncoder().encode(\n        '{\"key\": \"value\", \"number\": 123}\\r\\n'\n      ));\n      controller.enqueue(new TextEncoder().encode(\n        '--BOUNDARY--\\r\\n'\n      ));\n      controller.close();\n    }\n  });\n\n  // A mock Response object with a 'body' property\n  const mockResponse = { \n    body: dummyStream,\n    headers: new Headers({'content-type': 'multipart/mixed; boundary=BOUNDARY'})\n  };\n\n  for await (const message of parseMultipartStream(mockResponse as Response)) {\n    console.log(\"\\n--- New Message ---\");\n    console.log(\"Headers:\");\n    for (const [key, value] of message.headers.entries()) {\n      console.log(`  ${key}: ${value}`);\n    }\n\n    const contentType = message.headers.get(\"content-type\");\n    const customHeader = message.headers.get(\"x-custom-header\");\n\n    console.log(\"Content-Type:\", contentType);\n\n    let payloadContent = '';\n    const reader = message.payload.getReader();\n    while (true) {\n      const { done, value } = await reader.read();\n      if (done) break;\n      payloadContent += new TextDecoder().decode(value);\n    }\n    console.log(\"Payload (full):\");\n    console.log(payloadContent.trim()); // Trim to remove potential trailing newlines from stream simulation\n  }\n}\n\nsimulateMultipartFetch().catch(console.error);","lang":"typescript","description":"Demonstrates how to parse a multipart/mixed stream, access headers, and stream the payload of each part. It includes a simulated multipart response for a runnable example.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}