Socket
Socket
Sign inDemoInstall

stream-chain

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-chain

Chain functions as transform streams.


Version published
Weekly downloads
1.4M
increased by6.68%
Maintainers
1
Weekly downloads
 
Created

What is stream-chain?

The stream-chain npm package is designed to facilitate the creation and management of processing pipelines for streams. It allows you to chain together multiple stream processing steps in a flexible and efficient manner.

What are stream-chain's main functionalities?

Creating a Stream Chain

This code demonstrates how to create a stream chain that parses JSON data, picks a specific part of the JSON, and then streams the values. The pipeline processes a JSON string and logs the value of the 'data' key.

const { chain } = require('stream-chain');
const { parser } = require('stream-json');
const { pick } = require('stream-json/filters/Pick');
const { streamValues } = require('stream-json/streamers/StreamValues');

const pipeline = chain([
  parser(),
  pick({ filter: 'data' }),
  streamValues(),
]);

pipeline.on('data', (data) => {
  console.log(data.value);
});

pipeline.write('{"data": {"key": "value"}}');
pipeline.end();

Combining Multiple Streams

This example shows how to combine multiple streams in a chain to process an array of JSON objects. The pipeline parses the JSON, picks the 'items' array, and then streams each value in the array.

const { chain } = require('stream-chain');
const { parser } = require('stream-json');
const { pick } = require('stream-json/filters/Pick');
const { streamValues } = require('stream-json/streamers/StreamValues');
const { streamArray } = require('stream-json/streamers/StreamArray');

const pipeline = chain([
  parser(),
  pick({ filter: 'items' }),
  streamArray(),
  streamValues(),
]);

pipeline.on('data', (data) => {
  console.log(data.value);
});

pipeline.write('{"items": [{"key": "value1"}, {"key": "value2"}]}');
pipeline.end();

Other packages similar to stream-chain

Keywords

FAQs

Package last updated on 09 Oct 2024

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