Gathering detailed insights and metrics for co-busboy
Gathering detailed insights and metrics for co-busboy
npm install co-busboy
Typescript
Module System
Min. Node Version
Node Version
NPM Version
92.7
Supply Chain
98.4
Quality
81.8
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
9,708,608
Last Day
2,586
Last Week
16,596
Last Month
88,766
Last Year
1,168,829
154 Stars
63 Commits
24 Forks
10 Watching
1 Branches
14 Contributors
Minified
Minified + Gzipped
Latest Version
2.0.1
Package Id
co-busboy@2.0.1
Unpacked Size
12.24 kB
Size
4.55 kB
File Count
4
NPM Version
6.14.18
Node Version
18.16.0
Publised On
06 May 2023
Cumulative downloads
Total Downloads
Last day
-21.3%
2,586
Compared to previous day
Last week
-26.5%
16,596
Compared to previous week
Last month
-5.1%
88,766
Compared to previous month
Last year
-47.3%
1,168,829
Compared to previous year
4
4
busboy multipart parser using co
or koa
.
1const parse = require('co-busboy') 2 3app.use(async (next) => { 4 // the body isn't multipart, so busboy can't parse it 5 if (!this.request.is('multipart/*')) return await next() 6 7 const parts = parse(this) 8 let part 9 while (part = await parts()) { 10 if (part.length) { 11 // arrays are busboy fields 12 console.log('key: ' + part[0]) 13 console.log('value: ' + part[1]) 14 } else { 15 // otherwise, it's a stream 16 part.pipe(fs.createWriteStream('some file.txt')) 17 } 18 } 19 console.log('and we are done parsing the form!') 20})
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 co-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.
1const parse = require('co-busboy') 2 3app.use(async (next) => { 4 const parts = parse(this, { 5 autoFields: true 6 }) 7 let part 8 while (part = await parts()) { 9 // it's a stream 10 part.pipe(fs.createWriteStream('some file.txt')) 11 } 12 console.log('and we are done parsing the form!') 13 // .field holds all the fields in key/value form 14 console.log(parts.field._csrf) 15 // .fields holds all the fields in [key, value] form 16 console.log(parts.fields[0]) 17})
Use options.checkField
hook function(name, val, fieldnameTruncated, valTruncated)
can handle fields check.
1const parse = require('co-busboy') 2 3app.use(async (next) => { 4 const ctx = this 5 const parts = parse(this, { 6 checkField: (name, value) => { 7 if (name === '_csrf' && !checkCSRF(ctx, value)) { 8 var err = new Error('invalid csrf token') 9 err.status = 400 10 return err 11 } 12 } 13 }) 14 let part 15 while (part = await parts()) { 16 // ... 17 } 18})
Use options.checkFile
hook function(fieldname, file, filename, encoding, mimetype)
can handle filename check.
1const parse = require('co-busboy') 2const path = require('path') 3 4app.use(async (next) => { 5 const ctx = this 6 const parts = parse(this, { 7 // only allow upload `.jpg` files 8 checkFile: (fieldname, file, filename) => { 9 if (path.extname(filename) !== '.jpg') { 10 var err = new Error('invalid jpg image') 11 err.status = 400 12 return err 13 } 14 } 15 }) 16 let part 17 while (part = await parts()) { 18 // ... 19 } 20})
1const parse = require('co-busboy') 2const parts = parse(stream, { 3 autoFields: true 4})
options
are passed to busboy.
The only additional option is autoFields
.
Note: If busboy events partsLimit
, filesLimit
, fieldsLimit
is emitted, will throw an error.
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
or encoding
mimeType
or mime
Field[]
fieldname
value
valueTruncated
- Boolean
fieldnameTruncated
- BooleanIf falsey, then the parser is done.
If autoFields: true
, this object will be populated with key/value pairs.
If autoFields: true
, this array will be populated with all fields.
The MIT License (MIT)
Copyright (c) 2013 Jonathan Ong me@jongleberry.com Copyright (c) 2015 cojs and other contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
No security vulnerabilities found.