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

@basd/pipe

v0.0.4

Published

A simple and versatile utility class for handling streams in both Node.js and the browser.

Downloads

41

Readme

@basd/pipe

put that in your pipe and stream it

npm pipeline license downloads

Gitlab Twitter Discord

A simple and versatile utility class for handling streams in both Node.js and the browser. The Pipe class provides a convenient way to work with various stream types, including Readable, Writable, Duplex, Transform, and PassThrough streams. You can also collect readable streams into arrays, buffers and strings. Or pipe streams together to create a pipeline.

Installation

npm install @basd/pipe

Usage

First, require the Pipe class from the module:

const Pipe = require('@basd/pipe')

You can create different types of streams (Readable, Writable, Duplex, PassThrough) by using the Pipe class constructor and providing the appropriate options:

// Create a duplex stream (as a string)
const myDuplex = new Pipe('duplex')

// Create a readable stream (with an options object)
const myReadable = new Pipe({ type: 'readable' })

// Create a writable stream (without the new)
const myWritable = Pipe('writable')

// Create a pass-through stream (defaults to pass-through)
const myPassThrough = new Pipe()

You're basically creating a stream proxy that let's you pass a function and options into the constructor. If the type is a writable stream, the function becomes the write() method; if it's a readable stream, the function becomes the read() method.

const writer = new Pipe(data => console.log(`got data:`, data))
const reader = new Pipe()
const pipeline = Pipe.line(reader, writer)
pipeline.push('Hello World!') // => `got data: Hello World!`

The Pipe class can also be used to set up custom write and read handlers:

const myDuplex = new Pipe(
  'duplex',
  {
    write: (data, encoding, callback) => {
      console.log('Writing:', data)
      callback()
    },
    read: (size) => {
      console.log('Reading:', size)
    }
  }
)

You can pipe other Pipe instances or functions into a Pipe instance:

const myDuplex = new Pipe('duplex')
const myReadable = new Pipe('readable')

myDuplex.pipe(myReadable)

The line method allows you to pipe multiple streams one after the other:

const myDuplex = new Pipe('duplex')
const myReadable = new Pipe('readable')
const myWritable = new Pipe('writable')

myDuplex.line(myReadable, myWritable)

You can collect data from a stream:

const myReadable = new Pipe('readable')

myReadable.collect().then((data) => {
  console.log('Collected data:', data)
})

And write data to a stream:

const myWritable = new Pipe('writable')

Pipe.writeStream(myWritable, 'Hello, world!').then(() => {
  console.log('Data written.')
})

Or read data from a stream:

const myReadable = new Pipe('readable')

Pipe.readStream(myReadable).then((data) => {
  console.log('Read data:', data)
})

Documentation

Pipe Class Methods

The Pipe class provides several static methods and properties to work with different stream types:

  • Pipe.Duplex
  • Pipe.Readable
  • Pipe.Writable
  • Pipe.Transform
  • Pipe.PassThrough
  • Pipe.line(...)
  • Pipe.collect(stream, format = 'array', bytes = 32)
  • Pipe.readStream(reader)
  • Pipe.writeStream(writer, data)

Pipe Instance Methods

The Pipe class instances expose a set of methods to interact with the underlying stream:

  • pipe.end(...)
  • pipe.removeListener(...)
  • pipe.on(...)
  • pipe.once(...)
  • pipe.off(...)
  • pipe.emit(...)
  • pipe.write(...)
  • pipe.read(...)
  • pipe.push(...)
  • pipe.pipe(pipe)
  • pipe.line(...)
  • pipe.collect()

API Reference

API Reference, also see the inline comments in the Pipe class for more detailed information about each method.

Tests

In order to run the test suite, simply clone the repository and install its dependencies:

git clone https://gitlab.com/frenware/core/basd/pipe.git
cd basd
npm install

To run the tests:

npm test

Contributing

Thank you! Please see our contributing guidelines for details.

Donations

If you find this project useful and want to help support further development, please send us some coin. We greatly appreciate any and all contributions. Thank you!

Bitcoin (BTC):

1JUb1yNFH6wjGekRUW6Dfgyg4J4h6wKKdF

Monero (XMR):

46uV2fMZT3EWkBrGUgszJCcbqFqEvqrB4bZBJwsbx7yA8e2WBakXzJSUK8aqT4GoqERzbg4oKT2SiPeCgjzVH6VpSQ5y7KQ

License

basd is MIT licensed.