await-busboy
Advanced tools
Comparing version 1.0.0 to 1.0.1
1.0.1 / 2017-03-07 | ||
================== | ||
* tests; support node 4,6,7,8-nightly | ||
* tests; add co-busboy tests | ||
* docs; updated | ||
1.0.0 / 2017-03-05 | ||
@@ -3,0 +10,0 @@ ================== |
@@ -0,1 +1,3 @@ | ||
'use strict' | ||
const Busboy = require('busboy') | ||
@@ -2,0 +4,0 @@ const BlackHoleStream = require('black-hole-stream') |
{ | ||
"name": "await-busboy", | ||
"description": "An awaitable busboy multipart parser", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"author": { | ||
@@ -27,2 +27,3 @@ "name": "Aaron Heckmann", | ||
"devDependencies": { | ||
"co": "4.6.x", | ||
"istanbul": "0.4.x", | ||
@@ -37,10 +38,11 @@ "formstream": "1.0.x", | ||
"lint-fix": "NODE_ENV=test node_modules/standard/bin/cmd.js --fix", | ||
"test-cov": "NODE_ENV=test istanbul cover _mocha -- --reporter spec --bail", | ||
"test-cov": "NODE_ENV=test istanbul cover _mocha -- --reporter spec --bail test/index.js", | ||
"open-cov": "open coverage/lcov-report/index.html", | ||
"test-only": "NODE_ENV=test mocha --reporter spec --bail" | ||
"test-only": "NODE_ENV=test mocha --reporter spec --bail test/index.js" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"result.js" | ||
"result.js", | ||
"LICENSE.md" | ||
] | ||
} |
#await-busboy | ||
[busboy][] with `async/await` support. | ||
[busboy][] multipart parser with `async/await` and [koa][]/[co][] `yield` support. | ||
@@ -22,2 +22,4 @@ [![NPM version][npm-image]][npm-url] | ||
[busboy]: https://github.com/mscdex/busboy | ||
[co]: https://github.com/tj/co | ||
[koa]: https://github.com/koajs/koa | ||
@@ -151,2 +153,36 @@ _forked from https://github.com/cojs/busboy and updated to support async/await_ | ||
### co, koa and yield support | ||
This module is backward compatible with [koa][], [co][] and `yield` syntax. | ||
```js | ||
const Koa = require('koa') | ||
const app = new Koa() | ||
const parse = require('await-busboy') | ||
app.use(function* (ctx, next) { | ||
// the body isn't multipart, we can't parse it | ||
if (!ctx.request.is('multipart/*')) return yield next | ||
const parts = parse(ctx) | ||
try { | ||
let part | ||
while ((part = yield parts)) { | ||
if (part.length) { | ||
// arrays are await-busboy fields | ||
console.log({ key: part[0], value: part[1] }) | ||
} else { | ||
// otherwise, it's a stream | ||
part.pipe(someOtherStream) | ||
} | ||
} | ||
} catch (err) { | ||
return ctx.throw(err) | ||
} | ||
ctx.body = 'await-busboy is done parsing the form!' | ||
}); | ||
``` | ||
## API | ||
@@ -198,3 +234,2 @@ | ||
## Development | ||
@@ -201,0 +236,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14491
185
246
5