<commit_before># co busboy

[busboy](http://github.com/mscdex/busboy) multipart parser using `co` or `koa`.

## Example

```js
var parse = require('co-busboy')

app.use(function* (next) {
  // the body isn't multipart, so busboy can't parse it
  if (!this.request.is('multipart/*')) return yield next
  
  var parts = parse(this)
  var part
  while (part = yield parts) {
    if (part.length) {
      // arrays are busboy fields
      console.log('key: ' + part[0])
      console.log('value: ' + part[1])
    } else {
      // otherwise, it's a stream
      part.pipe(fs.createWriteStream('some file.txt'))
    }
  }
  console.log('and we are done parsing the form!')
})
```

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.

```js
var parse = require('co-busboy')

app.use(function* (next) {
  var parts = parse(this)
  var part
  while (part = yield parts) {
    // it's a stream
    part.pipe(fs.createWriteStream('some file.txt'))
  }
  console.log('and we are done parsing the form!')
  // .field holds all the fields in key/value form
  console.log(parts.field._csrf)
  // .fields holds all the fields in [key, value] form
  console.log(parts.fields[0])
})
```

## API

### parts = parse(stream, [options])

```js
var parse = require('co-busboy')
var parts = parse(stream {
  autoFields: true
})
```

`options` are passed to busboy.<commit_msg>fix autoFields in readme<commit_after># co busboy

[busboy](http://github.com/mscdex/busboy) multipart parser using `co` or `koa`.

## Example

```js
var parse = require('co-busboy')

app.use(function* (next) {
  // the body isn't multipart, so busboy can't parse it
  if (!this.request.is('multipart/*')) return yield next

  var parts = parse(this)
  var part
  while (part = yield parts) {
    if (part.length) {
      // arrays are busboy fields
      console.log('key: ' + part[0])
      console.log('value: ' + part[1])
    } else {
      // otherwise, it's a stream
      part.pipe(fs.createWriteStream('some file.txt'))
    }
  }
  console.log('and we are done parsing the form!')
})
```

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.

```js
var parse = require('co-busboy')

app.use(function* (next) {
  var parts = parse(this, {
    autoFields: true
  })
  var part
  while (part = yield parts) {
    // it's a stream
    part.pipe(fs.createWriteStream('some file.txt'))
  }
  console.log('and we are done parsing the form!')
  // .field holds all the fields in key/value form
  console.log(parts.field._csrf)
  // .fields holds all the fields in [key, value] form
  console.log(parts.fields[0])
})
```

## API

### parts = parse(stream, [options])

```js
var parse = require('co-busboy')
var parts = parse(stream, {
  autoFields: true
})
```

`options` are passed to busboy.
{'fraction_non_alphanumeric': 0.13496376811594202, 'fraction_numerical': 0.0018115942028985507, 'mean_word_length': 3.347769028871391, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5638942', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1071, 'n_words': 378}