{"id":13592200,"url":"https://github.com/mscdex/dicer","last_synced_at":"2025-04-08T08:15:34.505Z","repository":{"id":7255476,"uuid":"8567106","full_name":"mscdex/dicer","owner":"mscdex","description":"A very fast streaming multipart parser for node.js","archived":false,"fork":false,"pushed_at":"2023-07-15T15:17:38.000Z","size":90,"stargazers_count":187,"open_issues_count":8,"forks_count":37,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-01T05:35:46.492Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mscdex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2013-03-04T23:00:42.000Z","updated_at":"2025-02-20T08:28:29.000Z","dependencies_parsed_at":"2022-08-18T07:21:22.617Z","dependency_job_id":"2f543f0e-c744-43f1-9839-2222731392d4","html_url":"https://github.com/mscdex/dicer","commit_stats":{"total_commits":104,"total_committers":4,"mean_commits":26.0,"dds":"0.028846153846153855","last_synced_commit":"c64ada8f65b4966439880f04ae216ef65ddc8243"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fdicer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fdicer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fdicer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fdicer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mscdex","download_url":"https://codeload.github.com/mscdex/dicer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247801175,"owners_count":20998339,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T16:01:06.878Z","updated_at":"2025-04-08T08:15:34.483Z","avatar_url":"https://github.com/mscdex.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"\nDescription\n===========\n\nA very fast streaming multipart parser for node.js.\n\nBenchmarks can be found [here](https://github.com/mscdex/dicer/wiki/Benchmarks).\n\n\nRequirements\n============\n\n* [node.js](http://nodejs.org/) -- v10.0.0 or newer\n\n\nInstall\n============\n\n    npm install dicer\n\n\nExamples\n========\n\n* Parse an HTTP form upload\n\n```js\nconst { inspect } = require('util');\nconst http = require('http');\n\nconst Dicer = require('dicer');\n\n// Quick and dirty way to parse multipart boundary\nconst RE_BOUNDARY =\n  /^multipart\\/.+?(?:; boundary=(?:(?:\"(.+)\")|(?:([^\\s]+))))$/i;\nconst HTML = Buffer.from(`\n  \u003chtml\u003e\u003chead\u003e\u003c/head\u003e\u003cbody\u003e\n    \u003cform method=\"POST\" enctype=\"multipart/form-data\"\u003e\n      \u003cinput type=\"text\" name=\"textfield\"\u003e\u003cbr /\u003e\n      \u003cinput type=\"file\" name=\"filefield\"\u003e\u003cbr /\u003e\n      \u003cinput type=\"submit\"\u003e\n    \u003c/form\u003e\n  \u003c/body\u003e\u003c/html\u003e\n`);\nconst PORT = 8080;\n\nhttp.createServer((req, res) =\u003e {\n  let m;\n  if (req.method === 'POST'\n      \u0026\u0026 req.headers['content-type']\n      \u0026\u0026 (m = RE_BOUNDARY.exec(req.headers['content-type']))) {\n    const d = new Dicer({ boundary: m[1] || m[2] });\n\n    d.on('part', (p) =\u003e {\n      console.log('New part!');\n      p.on('header', (header) =\u003e {\n        for (const h in header) {\n          console.log(\n            `Part header: k: ${inspect(h)}, v: ${inspect(header[h])}`\n          );\n        }\n      });\n      p.on('data', (data) =\u003e {\n        console.log(`Part data: ${inspect(data.toString())}`);\n      });\n      p.on('end', () =\u003e {\n        console.log('End of part\\n');\n      });\n    });\n    d.on('finish', () =\u003e {\n      console.log('End of parts');\n      res.writeHead(200);\n      res.end('Form submission successful!');\n    });\n    req.pipe(d);\n  } else if (req.method === 'GET' \u0026\u0026 req.url === '/') {\n    res.writeHead(200);\n    res.end(HTML);\n  } else {\n    res.writeHead(404);\n    res.end();\n  }\n}).listen(PORT, () =\u003e {\n  console.log(`Listening for requests on port ${PORT}`);\n});\n```\n\n\nAPI\n===\n\n_Dicer_ is a _Writable_ stream\n\nDicer (special) events\n----------------------\n\n* **finish**() - Emitted when all parts have been parsed and the Dicer instance has been ended.\n\n* **part**(\u003c _PartStream_ \u003estream) - Emitted when a new part has been found.\n\n* **preamble**(\u003c _PartStream_ \u003estream) - Emitted for preamble if you should happen to need it (can usually be ignored).\n\n* **trailer**(\u003c _Buffer_ \u003edata) - Emitted when trailing data was found after the terminating boundary (as with the preamble, this can usually be ignored too).\n\n\nDicer methods\n-------------\n\n* **(constructor)**(\u003c _object_ \u003econfig) - Creates and returns a new Dicer instance with the following valid `config` settings:\n\n    * **boundary** - _string_ - This is the boundary used to detect the beginning of a new part.\n\n    * **headerFirst** - _boolean_ - If true, preamble header parsing will be performed first.\n\n    * **maxHeaderPairs** - _integer_ - The maximum number of header key=\u003evalue pairs to parse **Default:** 2000 (same as node's http).\n\n* **setBoundary**(\u003c _string_ \u003eboundary) - _(void)_ - Sets the boundary to use for parsing and performs some initialization needed for parsing. You should only need to use this if you set `headerFirst` to true in the constructor and are parsing the boundary from the preamble header.\n\n\n\n_PartStream_ is a _Readable_ stream\n\nPartStream (special) events\n---------------------------\n\n* **header**(\u003c _object_ \u003eheader) - An object containing the header for this particular part. Each property value is an _array_ of one or more string values.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmscdex%2Fdicer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmscdex%2Fdicer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmscdex%2Fdicer/lists"}