npm.io
0.4.1 • Published 4 years ago

memstreams

Licence
MIT
Version
0.4.1
Deps
2
Size
31 kB
Vulns
0
Weekly
0

Memory Stream

build status npm Snyk Vulnerabilities for GitHub Repo Code Climate coverage Code Climate maintainability Greenkeeper badge Greenkeeper badge node npm type definitions GitHub

Memory Streams library for JavaScript based on readable-stream

This library is forked from stream-mock

Features

  • Create a readable stream from any iterable.
  • Create a writable stream that puts its data at your disposal.
  • Create a duplex stream that combines a readable and writable stream together.
  • Can operate both in object and normal ( Buffer ) mode.
  • Forward writable to readable through event write to replace queue

Quick start

yarn add memstreams

Or, if you are more a npm person

npm i memstreams
Basic usage

You are building an awesome brand new Transform stream that rounds all your values.

rounder.ts

import {Transform} from 'stream';

export class Rounder extends Transform {
  _transform(chunk, encoding, callback) {
    this.push(Math.round(chunk));
    callback();
  }
}

Now you need / want to test it.

example.ts

import {ObjectReader, ObjectWriter} from 'memstreams';
import {Rounder} from './rounder';

const input = [1.2, 2.6, 3.7];
const transform = new Rounder({objectMode: true});
const reader = new ObjectReader(input, {autoEnd: true});
const writer = new ObjectWriter();

reader.pipe(transform).pipe(writer);

writer.on('finish', () => {
  console.log(writer.data);
});

License

MIT