Skip to content
This repository has been archived by the owner on Dec 16, 2020. It is now read-only.

Latest commit

 

History

History
108 lines (70 loc) · 2.04 KB

PureStream.md

File metadata and controls

108 lines (70 loc) · 2.04 KB

PureStream

This is the object stream instance.

constructor

Create a new instance of PureStream
You wouldn't normally create a stream this way, instead you would use transformers.

import {PureStream} from 'pure-stream';

const stream  = new PureStream({
  highWaterMark: 1
});

pipe

Pipe from one stream to another.
Errors are propagated from the source to the destination.

import {PureStream} from 'pure-stream';

new PureStream().pipe(new PureStream());

write

Write a value to the stream.
Returns false if the stream wishes for the calling code to wait for the 'drain' event to be emitted before continuing to write additional data; otherwise true.

import {PureStream} from 'pure-stream';

const written = new PureStream().write(1);

destroy

Destroy the stream and end with an error.

import {PureStream} from 'pure-stream';

new PureStream().destroy(new Error('Bad));

end

Ends a stream gracefully.
Takes an optional value that is written to the stream before end.

import {PureStream} from 'pure-stream';

new PureStream().end();

each

Calls the given method when data is received.

import {PureStream} from 'pure-stream';

new PureStream().each((value) => console.log(value));

done

Calls the given method when the stream ends.
The first argument will be an error if one occurred.

import {PureStream} from 'pure-stream';

new PureStream().done((err) => console.log('Stream ended', err));

toPromise

Convert the stream into a promise that resolves to an array of each item in the stream.

import {PureStream} from 'pure-stream';

const stream = new PureStream();
stream.write(1);
stream.write(2);
stream.toPromise(); // Promise<[1, 2]>

toNodeStream

Convert the stream into a node passthrough stream.

import {PureStream} from 'pure-stream';

const stream = new PureStream();
stream.write(1);
stream.write(2);

const nodeStream = stream.toNodeStream();
nodeStream.on('data', () => {}); // 1, 2