Socket
Socket
Sign inDemoInstall

lifion-aws-event-stream

Package Overview
Dependencies
4
Maintainers
4
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    lifion-aws-event-stream

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


Version published
Weekly downloads
2.3K
decreased by-17.58%
Maintainers
4
Install size
216 kB
Created
Weekly downloads
 

Changelog

Source

v1.0.7 (2019-11-11)

Readme

Source

lifion-aws-event-stream

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

Getting Started

To install the module:

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

The module exports a parse function and a Parser stream. To use the parse function:

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

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

To use the Parser stream:

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:

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:

API Reference

eventStream.Parser ⇐ Transform

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 lifion-aws-event-stream
Extends: Transform
See: https://nodejs.org/dist/latest-v10.x/docs/api/stream.html#stream_class_stream_transform

eventStream.parse(buffer) ⇒ object

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

Kind: static method of lifion-aws-event-stream
Returns: object - The parsed vnd.amazon.eventstream object.
Throws:

  • Error 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.
ParamTypeDescription
bufferBufferThe buffer to parse.

License

MIT

Keywords

FAQs

Last updated on 11 Nov 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc