# multipart-read-stream

> Read a multipart stream over HTTP

Latest version **3.0.1** (published 2017-06-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install multipart-read-stream
pnpm add multipart-read-stream
yarn add multipart-read-stream
bun add multipart-read-stream
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2017-06-05 |
| First published | 2016-10-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 13 |
| Maintainers | davidmarkclements, yoshuawuyts |
| Keywords | http, multipart, stream |

## Links

- npm: https://www.npmjs.com/package/multipart-read-stream
- Repository: https://github.com/yoshuawuyts/multipart-read-stream
- Homepage: https://github.com/yoshuawuyts/multipart-read-stream#readme
- Issues: https://github.com/yoshuawuyts/multipart-read-stream/issues
- npm.io page: https://npm.io/package/multipart-read-stream

## Dependencies (3)

- [pez](https://npm.io/package/pez.md) ^2.1.4
- [xtend](https://npm.io/package/xtend.md) ^4.0.1
- [content](https://npm.io/package/content.md) ^3.0.3

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 3.0.1 (latest) — 2017-06-05
- 3.0.0 — 2017-02-16
- 2.0.0 — 2016-12-20
- 1.0.1 — 2016-10-31
- 1.0.0 — 2016-10-20

## README

# multipart-read-stream [![stability][0]][1]
[![npm version][2]][3] [![build status][4]][5] [![test coverage][6]][7]
[![downloads][8]][9] [![js-standard-style][10]][11]

Read a multipart stream over HTTP. Built on top of [pez][pez].

## Usage
```js
var multipart = require('multipart-read-stream')
var pump = require('pump')
var http = require('http')

http.createServer(function (req, res) {
  var multipartStream = multipart(req.headers, handler)

  pump(req, multipartStream, function (err) {
    if (err) res.end('server error')
    res.end()
  })

  function handler (fieldname, file, filename) {
    console.log('reading file ' + filename + ' from field ' + fieldname)
    var fileStream = fs.createWriteStream(path.join('/tmp', filename))
    pump(file, fileStream)
  }
}).listen(8080)
```

## API
### readableStream = multipart(headers, [options], fileHandler)
Create a new multipart stream handler. Takes the following arguments:
- __headers:__ an object containing request headers (typically: `req.headers`)
- __options:__ an object that is passed directly to [pez][pez]
- __filehandler(fieldname, file, filename, encoding, mimetype):__ handle a
  file. Each `file` is a `readableStream`

### Events
multipart-read-stream returns an instance (from `pez.Dispenser`) which
emits a number of multipart specific events:

#### readableStream.on('part', cb(stream))
The `part` event drives the `fileHandler` callback for the main API.
The difference is it supplies a single parameter, the read stream of the
file data of a multipart section.

#### readableStream.on('field', cb(name, value))
A field event is emitted for partitions containing key-value data
(instead of file data).

#### readableStream.on('preamble', cb(str))
Multipart data *may* have a preamble section, which is typically
ignored by parsers. However it's sometimes used as an area to
contain hints/meta information.

#### readableStream.on('epilogue', cb(str))
As with the preamble section, the epilogue section essentially
has the same role (ignored, but can be used for meta data), except
it will be parsed after the body rather than before.

## Installation
```sh
$ npm install --save multipart-read-stream
```

## License
[MIT](https://tldrlegal.com/license/mit-license)

[0]: https://img.shields.io/badge/stability-experimental-orange.svg?style=flat-square
[1]: https://nodejs.org/api/documentation.html#documentation_stability_index
[2]: https://img.shields.io/npm/v/multipart-read-stream.svg?style=flat-square
[3]: https://npmjs.org/package/multipart-read-stream
[4]: https://img.shields.io/travis/yoshuawuyts/multipart-read-stream/master.svg?style=flat-square
[5]: https://travis-ci.org/yoshuawuyts/multipart-read-stream
[6]: https://img.shields.io/codecov/c/github/yoshuawuyts/multipart-read-stream/master.svg?style=flat-square
[7]: https://codecov.io/github/yoshuawuyts/multipart-read-stream
[8]: http://img.shields.io/npm/dm/multipart-read-stream.svg?style=flat-square
[9]: https://npmjs.org/package/multipart-read-stream
[10]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
[11]: https://github.com/feross/standard
[pez]: https://github.com/hapijs/pez

---
_Source: https://npm.io/package/multipart-read-stream · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
