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

@iaigz/stream-io

v1.7.11

Published

Pipeable spawned processes

Downloads

653

Readme

@iaigz/stream-io

Pipeable subprocesses

This is an utility to pipe to/from spawned child processes likewise a command line pipeline.

IOStream is responsible of ONE, and only one, Input-Output operation.

Internally, it wraps a Subprocess whoose standard input can be reached through the Writable stream interface; and whoose standard output can be consumed from the Readable stream counterpart.

[[TOC]]

Install

You may install this package either:

# using npm's gitlab support
npm install gitlab:iaigz/stream-io
# using npm.org public registry
npm install @iaigz/stream-io
# using gitlab.com @iaigz's npm package registry
npm config set @iaigz:registry=https://gitlab.com/api/v4/packages/npm/
npm install @iaigz/stream-io

Code example

const IOStream = require('@iaigz/stream-io')

// Ofc, we may pipe from any Readable source
process.stdin
  // Just pass data through
  .pipe(new IOStream('cat'))
  // Ofc, we may pipe to any Writable destination
  .pipe(process.stdout)

// WARN: favour usage of stream.pipeline() over Readable.pipe()
// see https://nodejs.org/docs/latest-v20.x/api/stream.html#streampipelinesource-transforms-destination-callback

For a more complete - but also useless - example, see example/jq.js

Test & Lint

A script is provided to run the suite. Once cloned, install deps and run it.

npm ci

npm test
# or
bash script/test
bash script/lint

Linting is done with standard, so code style meets standard style.


Knowledge Gems

The following tips are things I've found useful to understand streams better

Difference between Transform and Duplex

Time have elapsed since I messed-up with the Duplex aproach. Time ago I I thought IO may perform operations with data which aren't a transform - in the sense of transformation - but some day I found the following wonderful piece of knowledge at SO

Duplex Stream

A Duplex stream can be thought of a readable stream with a writable stream. Both are independent and each have separate internal buffer. The reads and writes events happen independently.

              ------------------|
        Read  <-----               External Source
You           ------------------|
        Write ----->               External Sink
              ------------------|
You don't get what you write. It is sent to another source.

Transform Stream

A Transform stream is a duplex where the read and write takes place in a causal way. The end points of the duplex stream are linked via some transform. Read requires write to have occurred.

               --------------|--------------
You     Write  ---->                   ---->  Read  You
               --------------|--------------
You write something, it is transformed, then you read something.

Conclusion

The EUREKA there is the linear flow input => output which a Transform stream eases significantly, whereas Duplex feels a kind of bi-directional beast.

That post has credits on why stream-io implements a Transform instead of a Duplex. It simplifies the whole thing, while technicaly an IO may not be writable at all (commands expecting no input) but produce readable output.

Backpressuring

There is a good guide about backpressuring at nodejs.org