await-busboy
busboy multipart parser with async/await
and koa/co yield
support.
forked from https://github.com/cojs/busboy and updated to support async/await
Example
const Koa = const app = const parse = app; app;
Note that parts will be delievered in the order they are defined in the form. Put your CSRF token first in the form and your larger files last.
If you want await-busboy
to automatically handle the fields,
set the autoFields: true
option.
Now all the parts will be streams and a field object and array will automatically be populated.
const Koa = const app = const parse = app
Example for csrf check
Use options.checkField
hook function(name, val, fieldnameTruncated, valTruncated)
can handle fields check.
const parse = app
Example for filename extension check
Use options.checkFile
hook function(fieldname, file, filename, encoding, mimetype)
can handle filename check.
const parse = const path = app
co, koa and yield support
This module is backward compatible with koa, co and yield
syntax.
const Koa = const app = const parse = app;
API
parts = parse(stream, [options])
const parse = const parts =
options
are passed to busboy.
The only additional option is autoFields
.
Note: If busboy events partsLimit
, filesLimit
, fieldsLimit
is emitted, will throw an error.
part = await parts
await the next part.
If autoFields: true
, this will always be a file stream.
Otherwise, it will be a field as an array.
-
Readable Stream
fieldname
filename
transferEncoding
orencoding
mimeType
ormime
-
Field[]
fieldname
value
valueTruncated
-Boolean
fieldnameTruncated
- Boolean
If falsey, then the parser is done.
parts.field{}
If autoFields: true
, this object will be populated with key/value pairs.
parts.fields[]
If autoFields: true
, this array will be populated with all fields.
Development
Running tests
npm test
runs tests + code coverage + lintnpm run lint
runs lint onlynpm run lint-fix
runs lint and attempts to fix syntax issuesnpm run test-cov
runs tests + test coveragenpm run open-cov
opens test coverage results in your browsernpm run test-only
runs tests only