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

buffed

v1.0.0

Published

Acts as a stream to send a buffer, gather buffers, or both.

Downloads

5

Readme

buffed

Build Status npm version Coverage Status

Acts as a stream to send a buffer, gather a buffer, or both.

Install

npm install --save buffed

Usage

Show:

  1. using it as a source (a Readable with buffer content)
  2. using it as a sink (a Writable collecting buffer chunks)
  3. as both a source and a sink at once
  4. getting its class
  5. resetting an instance with a new buffer (to use as a source)
  6. resetting an instance with pipe(buffer) (to use as a source)
// reused in examples below.
var buffer = getSomeBuffer()

// NOTE: everywhere you see `buffer` as an arg to
// methods, including the constructor,
// you could provide an array of buffers instead.

// Piping out: Buffed as a source

// 1a. create instance with buffer to pipe out
var buffed = require('buffed')(buffer)

// 1b. pipe buffer to another stream
buffed.pipe(anotherStream)


// 2a. get buffed function to use to create instances
var Buffed = require('buffed')

// 2b. create an instance with a buffer and pipe it to another stream
Buffed(buffer).pipe(anotherStream)

//  or:
Buffed.pipe(buffer).pipe(anotherStream)


// Piping in: Buffed as a sink

// 3a. get buffed function to create an instance
var Buffed = require('buffed')

// 3b. create a source buffed
var sink = Buffed()

// combine 3a and 3b:
var sink = require('buffed')()

// 3c. use event to get full buffer from sink
sink.on('finish', function() {
  console.log('collected buffers:',sink.buffers)
  console.log('as single buffer:', sink.combine())
})

// 3d. pipe stream to buffed
anotherStream.pipe(sink)


// Both source and sink

// 4a. get instance from function (like 1a)
var buffed = require('buffed')(buffer)

// 4b. use event to get full buffer from it
buffed.on('finish', function() {
  console.log('collected buffers:',sink.buffers)
  console.log('as single buffer:', sink.combine())
})

// 4c. pipe to another stream and then back to itself
buffed.pipe(anotherStream).pipe(buffed)


// Separate instances for source and sink

// 5a. get function to create instances
var buffed = require('buffed')

// 5b. create a source
var source = buffed(buffer)

// 5c. create a sink
var sink = buffed()

// 5d. use event to get full buffer from sink
sink.on('finish', function() {
  console.log('collected buffers:',sink.buffers)
  console.log('as single buffer:', sink.combine())
})

// 5e. pipe source thru another stream to sink
source.pipe(anotherStream).pipe(sink)


// the Buffed class is also exported as a subproperty

// 6a. get class
var Buffed = require('buffed').Buffed

// 6b. create an instance as a source (has a buffer) (can be a sink, too)
var source = new Buffed(buffer)

// 6c. create an instance as a sink (no buffer)
var sink = new Buffed


// Reset buffed instance with new buffer

// 7a. create a buffed instance
var buffed = require('buffed')(buffer)

// 7b. use event to continue when it's done:
buffed.on('finish', function() {
  console.log('collected buffers:',sink.buffers)
  console.log('as single buffer:', sink.combine())

  // 7d. reuse it to pipe something else via reset
  buffed.reset(getNewBuffer()).pipe(differentStream).pipe(buffed)

  // OR:
  // 7e. call pipe with a buffer which does a reset and returns itself
  buffed.pipe(getNewBuffer()).pipe(differentStream).pipe(buffed)
})

// 7c. use buffed
buffed.pipe(anotherStream).pipe(buffed)


// ES6 version:
import Buffed from 'buffed'

const source = new Buffed(buffer)
const sink   = new Buffed()

source.pipe(anotherStream).pipe(sink)

sink.on('finish', () =>
  console.log('collected buffers:',sink.buffers)
  console.log('as single buffer:', sink.combine())
)

MIT License