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 🙏

© 2025 – Pkg Stats / Ryan Hefner

post-stream

v0.2.0

Published

efficiently and conveniently send number, string, boolean, null, undefined, object, buffer or stream to a stream.

Readme

post-stream

Efficiently and conveniently send number, string, boolean, null, undefined, object, buffer or stream to a stream.

npm install --save post-stream


API

Constructor

//Create a stream controler
new PostStream(config);

config:

  • readable readable stream
  • writable writable stream
  • duplex duplex stream (such as tcp socket)
  • maxSize data fragment max byte size, default 16MB. If when sending data greater than maxSize will throw a error. If when receiving data greater than maxSize ,this data will be discard.

StaticClassProperty

serialize(data: Array): Buffer

Serilize data. Pass a array, item type can be number, string, boolean, null, undefined, object or buffer.

parse(data: Buffer): Array

Parse data. Pass a has been serialized buffer.

ClassProperty

data: EventEmiter

This is a EventEmiter. Received data`s title is event name.

const ps = new PostStream({readable, writable});
ps.data.once('test', function(data){ data === 123 });
await ps.send('test', 123);
parseData: boolean

Parse received data. Default is true. If you set false, then you need use PostStream.parse to parse every received data.

const ps = new PostStream({readable, writable});
ps.parseData = false;
ps.data.once('test', function(data){
    const parsed = PostStream.parse(data); //return array
});
await ps.send('test', 123);

ClassMethod

send(title: string, ...data: any[]): Promise<void>

Send number, string, boolean, null, undefined, object or buffer to stream. The first argument must be a string, it is used for description the data. After that you can pass zero or more data as arguments. If a argument is object or array,it will be serialized( use JSON.stringify ). If you want send a buffer, don`t put it in object or array. This function will return a promise object.

const ps = new PostStream({readable, writable});
await ps.send('test');
await ps.send('test1', 123);
await ps.send('test2', 'string', 1, 3.5, true, null, undefined, { name: 'test' }, [1,2,3], Buffer.from('ttt'));
send(title: string, data: stream.Readable | stream.Duplex): Promise<void>;

Send a stream`s data to stream. You can only pass one stream as second argument. Other arguments will be ignore. Receiver side will receive a buffer, data comes from the send stream. This function will return a promise object.

const ps = new PostStream({readable, writable});
await ps.send('stream', fs.createReadStream('./testFile.txt'));
await ps.send('stream', fs.createReadStream('./testFile2.txt'));
sendSerializedData(title: string, data: Buffer): Promise<void>;

Directly send using PostStream.serialize serialized data.

const ps = new PostStream({readable, writable});
await ps.sendSerializedData('original', PostStream.serialize(['hello']));
close

close(): Promise<void>

Close readable stream and writable stream.

const ps = new PostStream({readable, writable});
await ps.close();

Event

'data'

Receive all data. This will be triggered when PostStream has received data. The first parameter is title, after that will be zero or more data, determined by when sending.

const ps = new PostStream(readableStream, writableStream);
ps.on('data', function (title, data1, data2[, ...data3]) { });
'end'

This will be triggered when the be controled stream trigger end event.

'close'

This will be triggered when the be controled stream trigger close event.

'error'

This will be triggered when the be controled stream trigger error event or when parsing data error.

Attention

If you want to use pipe to communicate with child process, you would better use two pipe instead of one. Because of don`t know why child send data to parent will lost one data fragment.(this is not this package`s problem)

//parent

const child_process = require('child_process');
const path = require('path');
const PostStream = require('post-stream');

const child = child_process.spawn(process.execPath, [path.resolve('./child.js')], {
    stdio: ['pipe', 'pipe', 'pipe', 'pipe', 'pipe']
});
const ps = new PostStream({readable:child.stdio[3], writable:child.stdio[4]});
ps.data.on('main', data => {
    console.log('main:', data)
});
ps.send('child',123);
//child
const fs = require('fs');
const PostStream = require('post-stream');

let readable = fs.createReadStream(null,{fd:4});
let writable = fs.createWriteStream(null,{fd:3});
const ps = new PostStream({readable, writable});
ps.data.on('child', data => {
    ps.send('main', data);
});