https://github.com/chjj/evilpart
A Node multipart parser that is positively evil
https://github.com/chjj/evilpart
Last synced: 17 days ago
JSON representation
A Node multipart parser that is positively evil
- Host: GitHub
- URL: https://github.com/chjj/evilpart
- Owner: chjj
- License: mit
- Created: 2011-05-04T23:34:54.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2011-05-12T12:26:25.000Z (almost 14 years ago)
- Last Synced: 2025-02-14T07:49:43.555Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 97.7 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Evilpart - a multipart parser that is positively evil.
## What is it?
Evilpart is the dirtiest, hackiest multipart parser you'll find.
## Why is it evil?
It's a single function (~40 lines) that expects a buffered request
body (multipart/form-data) to parse, so it's not streaming. It also uses
regexes to parse the body, which means it won't be able to parse binary
encoded parts.## No binary, no streaming, what's the point?
I specifically wrote this for parsing browser uploads of small text files (although,
it should in theory be able to handle base64 encoded parts). It will actually
be relatively efficient as long as all the data makes it into the first packet. So,
for text files under maybe 25-30kb, evilpart should do well. Also, frameworks like
express/connect will buffer the request body by default and expose the raw
request body as a string, so all you have to do is pass it in to a function.* * *
multipart can be complex, and I think its good to keep things simple,
especially if you only need to parse multipart for something small, like a
text file.## Usage
var evilpart = require('evilpart');
// need to pass in the raw content type header
// so evilpart can grab the boundary key
var parts = evilpart(req.headers['content-type'], req.rawBody);
console.log(parts.myfile);This may yield an object looking like this:
{
'myfile': {
name: 'myfile',
filename: 'myfile.txt',
data: 'hello world'
},
'other_field': {
name: 'other_field',
data: 'look! another form field.'
}
}