npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lifion-aws-event-stream

v1.0.7

Published

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

Downloads

11,284

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:

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:

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

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.

| Param | Type | Description | | ------ | ------------------- | -------------------- | | buffer | Buffer | The buffer to parse. |

License

MIT