{"name":"dicer","version":"0.2.2","author":{"name":"Brian White","email":"mscdex@mscdex.net"},"description":"A very fast streaming multipart parser for node.js","main":"./lib/Dicer","dependencies":{"streamsearch":"0.1.2","readable-stream":"1.1.x"},"scripts":{"test":"node test/test.js"},"engines":{"node":">=0.8.0"},"keywords":["parser","parse","parsing","multipart","form-data","streaming"],"licenses":[{"type":"MIT","url":"http://github.com/mscdex/dicer/raw/master/LICENSE"}],"repository":{"type":"git","url":"http://github.com/mscdex/dicer.git"},"bugs":{"url":"https://github.com/mscdex/dicer/issues"},"homepage":"https://github.com/mscdex/dicer","_id":"dicer@0.2.2","dist":{"shasum":"0905df5a8a6a1f91e9f60695e90d6d76768b97ed","tarball":"http://registry-npm.ywwl.com/dicer/download/dicer-0.2.2.tgz","integrity":"sha512-sXHq5G04iX2adPp3PcrJ7l7BlCm8W92W4Gb0pp/8NZ6Y14L38KZhys8x0ul9cvk8UEtiunRCXGxI800uS/IMwA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDX37JP3wMTYntg2MAB2K4yqv74vZ7ydnqDxuDveeMWLQIgf+NN1Xn1YptLB1sL/LNxsnT1Fjyg5mPi2VLo/1PfhME="}],"size":12993,"noattachment":false,"key":"/dicer/-/dicer-0.2.2.tgz"},"_from":"https://github.com/mscdex/dicer/tarball/v0.2.2","_resolved":"https://github.com/mscdex/dicer/tarball/v0.2.2","_npmVersion":"1.4.3","_npmUser":{"name":"mscdex","email":"mscdex@mscdex.net"},"maintainers":[{"name":"mscdex","email":"mscdex@mscdex.net"}],"directories":{},"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  <html><head></head><body>\n    <form method=\"POST\" enctype=\"multipart/form-data\">\n      <input type=\"text\" name=\"textfield\"><br />\n      <input type=\"file\" name=\"filefield\"><br />\n      <input type=\"submit\">\n    </form>\n  </body></html>\n`);\nconst PORT = 8080;\n\nhttp.createServer((req, res) => {\n  let m;\n  if (req.method === 'POST'\n      && req.headers['content-type']\n      && (m = RE_BOUNDARY.exec(req.headers['content-type']))) {\n    const d = new Dicer({ boundary: m[1] || m[2] });\n\n    d.on('part', (p) => {\n      console.log('New part!');\n      p.on('header', (header) => {\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) => {\n        console.log(`Part data: ${inspect(data.toString())}`);\n      });\n      p.on('end', () => {\n        console.log('End of part\\n');\n      });\n    });\n    d.on('finish', () => {\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' && req.url === '/') {\n    res.writeHead(200);\n    res.end(HTML);\n  } else {\n    res.writeHead(404);\n    res.end();\n  }\n}).listen(PORT, () => {\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**(< _PartStream_ >stream) - Emitted when a new part has been found.\n\n* **preamble**(< _PartStream_ >stream) - Emitted for preamble if you should happen to need it (can usually be ignored).\n\n* **trailer**(< _Buffer_ >data) - 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)**(< _object_ >config) - 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=>value pairs to parse **Default:** 2000 (same as node's http).\n\n* **setBoundary**(< _string_ >boundary) - _(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**(< _object_ >header) - An object containing the header for this particular part. Each property value is an _array_ of one or more string values.\n","publish_time":1393189419552,"_cnpm_publish_time":1393189419552,"dist-tags":{"latest":"0.3.1"}}