# lifion-aws-event-stream

> Node.js parser for the application/vnd.amazon.eventstream content-type.

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

## Install

```sh
npm install lifion-aws-event-stream
pnpm add lifion-aws-event-stream
yarn add lifion-aws-event-stream
bun add lifion-aws-event-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 | 1.0.7 |
| Published | 2019-11-11 |
| First published | 2018-09-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10.0.0 |
| Dependencies | 1 |
| Unpacked size | 27.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Edgardo Avilés |
| Maintainers | edgardo, kenzable, lifion.opensource, zaidmasud |
| Keywords | aws, aws-event-stream, cloud, content-type, event-stream, node, parser, stream |

## Links

- npm: https://www.npmjs.com/package/lifion-aws-event-stream
- Repository: https://github.com/lifion/lifion-aws-event-stream
- Homepage: https://github.com/lifion/lifion-aws-event-stream#readme
- Issues: https://github.com/lifion/lifion-aws-event-stream/issues
- npm.io page: https://npm.io/package/lifion-aws-event-stream

## Dependencies (1)

- [crc](https://npm.io/package/crc.md) ^3.8.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

- 1.0.7 (latest) — 2019-11-11
- 1.0.6 — 2019-10-18
- 1.0.5 — 2019-07-12
- 1.0.4 — 2019-04-24
- 1.0.3 — 2019-04-24
- 1.0.2 — 2019-02-27
- 1.0.1 — 2018-11-20
- 1.0.0 — 2018-10-04
- 1.0.0-alpha.1 — 2018-09-28

## README

# lifion-aws-event-stream

Node.js parser for binary streams under the **application/vnd.amazon.eventstream** content-type.

## Getting Started

To install the module:

```sh
npm install lifion-aws-event-stream --save
```

The module exports a [parse](#module_lifion-aws-event-stream.parse) function and a [Parser](#module_lifion-aws-event-stream.Parser) stream. To use the [parse](#module_lifion-aws-event-stream.parse) function:

```js
const { parse } = require('lifion-aws-event-stream');

const buffer = Buffer.from('000000100000000005c248eb7d98c8ff', 'hex');
console.log(parse(buffer)); // { headers: {}, payload: '' }
```

To use the [Parser](#module_lifion-aws-event-stream.Parser) stream:

```js
const { Parser } = require('lifion-aws-event-stream');

const parser = new Parser();
parser.on('data', console.log); // { headers: {}, payload: '' }

const buffer = Buffer.from('000000100000000005c248eb7d98c8ff', 'hex');
parser.write(buffer);
```

Pipe an HTTP response to parse the messages as they arrive:

```js
const got = require('got');
const { Parser } = require('lifion-aws-event-stream');
const { pipeline } = require('stream');

pipeline([
  got('/', …),
  new Parser(),
  new Writable({
    objectMode: true,
    write(data, encoding, callback) {
      console.log(data);
      callback();
    }
  }),
]);
```

This project's implementation is based on:

- https://github.com/aws/aws-sdk-ruby/tree/master/gems/aws-eventstream
- https://github.com/awslabs/aws-c-event-stream

## API Reference

- [lifion-aws-event-stream](#module_lifion-aws-event-stream)
  - [.Parser](#Parser) ⇐ <code>Transform</code>
  - [.parse(buffer)](#module_lifion-aws-event-stream.parse) ⇒ <code>object</code>

<a name="Parser"></a>

### eventStream.Parser ⇐ <code>Transform</code>

A transform stream that calls parse with the binary data written to it. Can be used to pipe
a response stream from an AWS service HTTP request. The stream will emit errors thrown during
parse calls.

**Kind**: static class of [<code>lifion-aws-event-stream</code>](#module_lifion-aws-event-stream)  
**Extends**: <code>Transform</code>  
**See**: https://nodejs.org/dist/latest-v10.x/docs/api/stream.html#stream_class_stream_transform  
<a name="module_lifion-aws-event-stream.parse"></a>

### eventStream.parse(buffer) ⇒ <code>object</code>

Parses the specified buffer with vnd.amazon.eventstream data into an object.

**Kind**: static method of [<code>lifion-aws-event-stream</code>](#module_lifion-aws-event-stream)  
**Returns**: <code>object</code> - The parsed vnd.amazon.eventstream object.  
**Throws**:

- <code>Error</code> Whenever:
  - The specified buffer has less than 16 bytes. The minimum vnd.amazon.eventstream message
    should have 4 bytes for the total length of the package, 4 bytes for the length of the
    headers section, 4 bytes for the checksum of the prelude, and finally 4 more bytes for
    the checksum of the entire message.
  - The total length as specified in the message doesn't matches the bufffer length.
  - The checksum of the prelude doesn't matches the calculated checksum.
  - The checksum of the message doesn't matches the calculated checksum.
  - The header value type is unknown.

| Param  | Type                | Description          |
| ------ | ------------------- | -------------------- |
| buffer | <code>Buffer</code> | The buffer to parse. |

## License

[MIT](./LICENSE)

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