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

stream-headerfooter

v1.1.3

Published

Transmit headers and footers at the start and end of streams.

Downloads

18

Readme

stream-headerfooter

Build Status

This module provides the ability to attach JSON headers and footers into any standard node/io.js stream pipeline to be consumed downstream. More specifically, this module provides:

  • The ability to pass JSON objects along streams when they first start (headers) and when they end (footers).
  • Header and Footer receivers are evented with 'header' and 'footer' events.
  • A simple, easy to use interface using stream piping.
  • Automatic stream sanitation after events are captured (headers and footers are removed from the pipeline after being consumed).
  • Flexible header/footer typing (string, number, object or array).

Installation

npm install --save stream-headerfooter

Basic usage

Include

var headerfooter = require('stream-headerfooter')

Attach Headers and Footers to an Outgoing Stream

You can attach JSON headers/footers to a special stream (headerfooter.Out) that encodes your headers and footers and sends them to be recieved later down your pipeline.

Make sure to add your header before your stream begins, and add your footer before your stream ends. This outgoing stream is a duplex transform stream, so it can be piped to AND from.

var outgoing = new headerfooter.Out()
outgoing.header = { name: "streamA", metadata:[23, 33, 221, 222] }
outgoing.footer = { exit_code: 2 }

Receive and Handle Incoming Headers and Footers

You'll need to create a special stream headerfooter.In to listen for headers and footers. This stream will emit header and footer events as they are received.

Just create event handlers to handle headers and footers from your stream. The incoming stream is also a duplex transform stream, so it can be piped to AND from.

var receiver = new headerfooter.In()

receiver.on('header', function(header) {
    console.log('Stream Header:', header)
})

receiver.on('footer', function(footer) {
    console.log('Stream Footer:', footer)
})

receiver.on('data', function(data) {
    console.log('Stream Data:', data) // sanitized stream data without header and footer data in buffer
})

Write and Receive!

Plug both these streams into your stream pipeline. The outgoing stream that has the headers on one end, and the receiver on the other end. header and footer events, as well as all other native node/io.js stream events can be captured (if they have handlers) on the receiving end.

var passthroughA = new PassThrough() // dummy
var passthroughB = new PassThrough() // dummy

passthroughA.pipe(outgoing).pipe(passthroughB)
passthroughB.pipe(receiver)

passthroughA.write('Testing... 123')
passthroughA.end("...Ending")

//=> Stream Header: { name: "streamA", metadata:[23, 33, 221, 222] }
//=> Stream Data: Testing... 123
//=> Stream Data: ...Ending
//=> Stream Footer: { exit_code: 2 }

License

The MIT License (MIT)
Copyright (c) 2015 Arjun Mehta