A stream that emits endless series of random bytes, with proper backpressure support.
A stream that sprays out random bytes at whoever's
read()-ing it or listening to
data. The implementation is surprisingly trivial thanks to
isaacs/readable-stream so I didn't have any tests but you should just take a good
look at the code if you are not sure.
RandStream class accepts a single option hash which is passed along as an
option to the inherited
Readable class with an exception of a few extra parameters:
var RandStream = ;var firehose =mode: 'alpha'defaultSize: 4096;firehose;
mode option maybe one of the following value:
0- A zero-filled streams. Essentially no longer random.
01- A zero-one stream. Useful to use as test streams that is a bit less boring :p
random- Default mode, using
crypto.randomBytesto generate data. The buffer is then pushed any reading clients untouched.
alpha- A stream of lowercase alphabets. Useful if you want to see the bytes being piped. The original sequence is generated using
alphabut generate a stream of digits.
randombut reads from a random start position in a pregenerated buffer of data.
defaultSize is the default size of the buffer to allocate when the underlying
_read implementation is not given a size.
This module can also be used from the command line if you install globally with
$ npm install -g randstream$ rand | hexdump -v
or with different mode and throttling rate:
$ rand alpha 16mcrqijnorspunxrkkeyehapnpfgqfbkzjfvkctxfdkm^C