0.4.1 • Published 2 years ago

memstreams v0.4.1

Weekly downloads
2
License
MIT
Repository
github
Last release
2 years ago

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

0.4.1

2 years ago

0.4.0

2 years ago

0.3.1

2 years ago

0.3.0

4 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago