🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

mississippi

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mississippi

a collection of useful streams

2.0.0
Source
npm
Version published
Weekly downloads
8.3M
-10.17%
Maintainers
2
Weekly downloads
 
Created

What is mississippi?

The 'mississippi' npm package is a collection of useful stream utility functions that make working with Node.js streams easier. It combines several smaller modules into one package, providing a comprehensive toolkit for stream operations.

What are mississippi's main functionalities?

pipe

The 'pipe' function is used to pipe data from one stream to another, handling errors and end-of-stream events automatically.

const miss = require('mississippi');
const fs = require('fs');

const readStream = fs.createReadStream('input.txt');
const writeStream = fs.createWriteStream('output.txt');

miss.pipe(readStream, writeStream, function(err) {
  if (err) {
    console.error('Pipe failed', err);
  } else {
    console.log('Pipe succeeded');
  }
});

each

The 'each' function allows you to process each chunk of data from a stream individually, providing a callback for each chunk and a final callback when the stream ends or an error occurs.

const miss = require('mississippi');
const fs = require('fs');

const readStream = fs.createReadStream('input.txt');

miss.each(readStream, function(chunk, next) {
  console.log('Chunk:', chunk.toString());
  next();
}, function(err) {
  if (err) {
    console.error('Each failed', err);
  } else {
    console.log('Each succeeded');
  }
});

concat

The 'concat' function collects all the data from a stream and concatenates it into a single buffer or string, providing it to a callback when the stream ends.

const miss = require('mississippi');
const fs = require('fs');

const readStream = fs.createReadStream('input.txt');

miss.concat(readStream, function(err, data) {
  if (err) {
    console.error('Concat failed', err);
  } else {
    console.log('Data:', data.toString());
  }
});

duplex

The 'duplex' function creates a duplex stream, which is both readable and writable. This is useful for creating custom streams that can process data in both directions.

const miss = require('mississippi');
const { Duplex } = require('stream');

const duplexStream = miss.duplex(new Duplex({
  read(size) {
    this.push('Hello, ');
    this.push('world!');
    this.push(null);
  },
  write(chunk, encoding, callback) {
    console.log('Received:', chunk.toString());
    callback();
  }
}));

duplexStream.on('data', (chunk) => {
  console.log('Data:', chunk.toString());
});

duplexStream.write('Test');

Other packages similar to mississippi

FAQs

Package last updated on 30 Jan 2018

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