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

@voliware/node-concat-transform

v0.1.0

Published

Concatenate data in a stream using a transform

Downloads

3

Readme

node-concat-transform

Concatenate data in a stream using a transform

Install

npm install @voliware/node-concat-transform

What is it?

In Node streams you may get data in small chunks. This is rare from a file, unless set explicitly, but will happen in a throttled network system. Most often you cannot operate on pieces of data beause you do not have the entire chunk of data. node-concat-transform is a Node Transform that you can use with the pipe() method to concatenate (link or bundle) data into one bigger chunk. Then, you can operate on that larger chunk if needed, and continue sending it downstream.

Why do I need it?

If you are using a readable Node stream that receives chunks and you are not 100% sure you will receive all the data at once, you will probbably need to bundle it first. You can easily accomplish this with node-concat-stream.

How do I use it?

Once you have a readable Node stream, such as a file stream, TCP stream, or any other type of Readable stream, you simply create a ConcatTransform and pass it into the pipe() method before you intend to do something with the stream data.

Example

Suppose you have a readable stream receiving chunks of data that is only 1 character in length. You can create a ConcatTransform to bundle the chunks into one big peice of data that can then be operated on. This would be essential for example when zipping stream data.

let readable = new Stream.Readable();
let concat_transform = new ConcatTransform();
let writable = new Stream.Writable();

// simulate a stream reading data 1 character/number at a time
for(let i = 0; i < data.length; i++){
    readable.read(data[i]);
}
// stream ends
readable.read(null);

// make use of the stream data
readable.pipe(concat_transform)
        .pipe(some_other_transform)
        .pipe(writable);

If you are receiving data that has a header, or a start delimiter and/or end delimiter, you can also set options for your ConcatTransform that will bundle the data based on these options. This is common in network based streams where an EOF set of characters, such as /r/n, indicate the end of a datagram, but you may actually get peices of the next or previous datagram in the same chunk. If your chunks have headers, than you will need to pass a custom function that parses the header and returns the total number of bytes expected in a fully formed chunk.

let concat_transform = new ConcatTransform({
    // strings or Buffers are accepted
    delimiter: {
        start: "START",
        end: "END"
    }
    // to parse a header, write a custom function
    // that will return the expected full chunk length
    header: header_parsing_function
});