randstream

A stream that emits endless series of random bytes, with proper backpressure support.

npm install randstream
17 downloads in the last month

RANDSTREAM

A stream that sprays out random bytes at whoever's read()-ing it or listening to its 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.

API

The exported 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 = require('randstream');

var firehose = new RandStream(
  { mode: 'alpha'
  , defaultSize: 4096
  });

firehose.pipe(process.stdout);

The 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.randomBytes to generate data. The buffer is then pushed any reading clients untouched.
  • pseudo - Uses crypto.pseudoRandomBytes instead.
  • alpha - A stream of lowercase alphabets. Useful if you want to see the bytes being piped. The original sequence is generated using crypto.randomBytes.
  • num - Like alpha but generate a stream of digits.

The defaultSize is the default size of the buffer to allocate when the underlying _read implementation is not given a size.

CLI

This module can also be used from the command line if you install globally with -g

$ npm install -g randstream
$ rand | hexdump -v

or with different mode and throttling rate:

$ rand alpha 16
mcrqijnorspunxrkkeyehapnpfgqfbkzjfvkctxfdkm^C

LICENSE

public domain.

npm loves you