Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

labeled-stream-splicer

Package Overview
Dependencies
Maintainers
40
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

labeled-stream-splicer

stream splicer with labels

  • 2.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
793K
decreased by-23.34%
Maintainers
40
Weekly downloads
 
Created

What is labeled-stream-splicer?

The labeled-stream-splicer package allows you to create a pipeline of streams that can be dynamically modified by adding, removing, or replacing streams at specific labels. This is particularly useful for complex stream processing tasks where the pipeline needs to be adjusted on the fly.

What are labeled-stream-splicer's main functionalities?

Creating a basic pipeline

This code demonstrates how to create a basic pipeline with two labeled steps. Each step is a through stream that logs the chunk it processes.

const splicer = require('labeled-stream-splicer');
const through = require('through2');

const pipeline = splicer([
  'step1', through.obj((chunk, enc, callback) => {
    console.log('Step 1:', chunk.toString());
    callback(null, chunk);
  }),
  'step2', through.obj((chunk, enc, callback) => {
    console.log('Step 2:', chunk.toString());
    callback(null, chunk);
  })
]);

pipeline.write('Hello, World!');
pipeline.end();

Dynamically adding a stream

This code shows how to dynamically add a new stream to the pipeline. The new stream is inserted before the existing 'step1' stream.

const splicer = require('labeled-stream-splicer');
const through = require('through2');

const pipeline = splicer([ 'step1', through.obj((chunk, enc, callback) => {
  console.log('Step 1:', chunk.toString());
  callback(null, chunk);
})]);

pipeline.write('Hello, World!');
pipeline.end();

pipeline.splice('step1', 0, through.obj((chunk, enc, callback) => {
  console.log('New Step:', chunk.toString());
  callback(null, chunk);
}));

pipeline.write('Hello again!');
pipeline.end();

Removing a stream

This code demonstrates how to remove a stream from the pipeline. The 'step2' stream is removed, so only 'step1' processes the input.

const splicer = require('labeled-stream-splicer');
const through = require('through2');

const pipeline = splicer([ 'step1', through.obj((chunk, enc, callback) => {
  console.log('Step 1:', chunk.toString());
  callback(null, chunk);
}), 'step2', through.obj((chunk, enc, callback) => {
  console.log('Step 2:', chunk.toString());
  callback(null, chunk);
})]);

pipeline.splice('step2', 1);

pipeline.write('Hello, World!');
pipeline.end();

Other packages similar to labeled-stream-splicer

Keywords

FAQs

Package last updated on 24 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc