# @slaviczavik/http-data-parser

> A really fast Node.js streaming multipart parser.

Latest version **2.1.0** (published 2019-11-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @slaviczavik/http-data-parser
pnpm add @slaviczavik/http-data-parser
yarn add @slaviczavik/http-data-parser
bun add @slaviczavik/http-data-parser
```

## 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 | 2.1.0 |
| Published | 2019-11-25 |
| First published | 2018-07-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 19.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jaroslav Zavodny |
| Maintainers | slaviczavik |
| Keywords | parser, multipart, upload, streaming, parse |

## Links

- npm: https://www.npmjs.com/package/@slaviczavik/http-data-parser
- Repository: https://github.com/slaviczavik/http-data-parser
- Homepage: https://github.com/slaviczavik/http-data-parser#readme
- Issues: https://github.com/slaviczavik/http-data-parser/issues
- npm.io page: https://npm.io/package/@slaviczavik/http-data-parser

## Dependencies (1)

- [@slaviczavik/stream-search](https://npm.io/package/@slaviczavik/stream-search.md) ^1.4.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 2.1.0 (latest) — 2019-11-25
- 2.0.0 — 2018-07-23
- 1.1.0 — 2018-07-22
- 1.0.0 — 2018-07-21

## README

[![Build Status](https://travis-ci.com/slaviczavik/http-data-parser.svg?branch=master)](https://travis-ci.com/slaviczavik/http-data-parser)

# Description
An extremely fast Node.js module for parsing form data and primarily file uploads.

# Requirements
Node.js 6.14.3 or higher is required.

# Installation
```
npm i @slaviczavik/http-data-parser
```

# Example

```JS
const HttpDataParser = require('@slaviczavik/http-data-parser')

// A boundary must be extracted from 'content-type' request header.
const boundary '--------------------------034172598905589540726558'
const parser = HttpDataParser(boundary)

parser.on('header', function (data, isLast) {
  // Save headers somewhere...

  if (isLast) {
    // Here you may prepare for handling body data,
    // like create a writable stream and so on.
  }
})

parser.on('data', function (data) {
  // Save body content somewhere...
})

parser.on('part', function () {
  // We reached the end of one body part.
  // Here we can concate body content together.
})

parser.on('end', function () {
  // We reached the end of whole body.
  // No other data will come.
})

req.on('data', function (data) {
  parser.write(data)
})

req.on('end', function () {
  parser.end()
})
```

# API

## Constructor
### `HttpDataParser(boundary)`

| Name | Required | Type | Description | Default
| - | - | - | - | - |
| `boundary` | true | `string` | | `none` |

## Methods
The parser is a Node.js Writable Stream, so you can use the `write` and the `end` methods,
or just only the `pipe` method.

### `write(buffer)`

| Parameter | Required | Type | Description
| - | - | - | - |
| `buffer` | true | `buffer` | Buffer from request body. |

### `end()`
Call this method when there is no more data to be consumed from the stream.

## Events

### `header(data, isLast)`
Emitted every time when a parser find a header part.

| Property | Type | Description
| - | - | - |
| `data` | `buffer` | - |
| `isLast` | `boolean` | Signals if it is a last header part. |

### `data(data)`
Emitted every time when a parser find a content data.

| Property | Type | Description
| - | - | - |
| `data` | `buffer` | - |

### `part()`
Emitted every time when a parser reach the end of one body part.

### `end()`
Emitted when a parser reached the end of request body.

---
_Source: https://npm.io/package/@slaviczavik/http-data-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
