memstreams
v0.4.1
Published
Memory Streams library for JavaScript based on readable-stream
Downloads
5
Maintainers
Readme
Memory Stream
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 replacequeue
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