1.0.0 • Published 9 years ago

stream-sample v1.0.0

Weekly downloads
3
License
ISC
Repository
github
Last release
9 years ago

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

parametertypedescription
sampleCountNumberthe 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