stream-sample

1.0.0 • Public • Published

stream-sample

build status

sample streams using reservoir sampling

stream-sample

Stream sampling uses a reservoir.

This implements the reservoir sampling algorithm that allows you to glean a statistically valid fixed-size sample from an unknown-size input while keeping only the sample in memory.

This module is different than the reservoir-stream module that requires the full input to be concatenated in memory.`

streamSample(sampleCount)

Create a transform stream that emits an evenly-distributed sample of sampleCount items for every new item received.

Parameters

parameter type description
sampleCount Number the number of elements to be placed in the sample.

Example

var streamSample = require('stream-sample');
 
var sampler = streamSample(10);
 
sampler.on('data', function(sample) {
  // sample is n items from the stream
});
 
for (var i = 0; i < 100; i++) sampler.push(Math.random());

Returns Stream.Transform, a transform stream that samples the input.

Installation

Requires nodejs.

$ npm install stream-sample

Tests

$ npm test

Package Sidebar

Install

npm i stream-sample

Weekly Downloads

2

Version

1.0.0

License

ISC

Last publish

Collaborators

  • tmcw