most-buffer
TypeScript icon, indicating that this package has built-in type declarations

0.0.11 • Public • Published

most-buffer

Version License

Gather most js streams events into buffers. Buffers are emitted according to a given event count or gather the complete stream if no count is given.

Installation

Using npm:

$ npm install --save most-buffer

In Node.js:

const buffer = require('most-buffer');

Usage

stream.thru(buffer(count)) -> Stream

stream:                 -a--b--c--------d--e--|
stream.thru(buffer(3)): -------[a,b,c]--------[d,e]|
  • count is the size of the buffer, if undefined the full stream will be buffered before being emitted as an array.

Examples

const most = require('most');
const buffer = require('most-buffer');
 
// Logs
// [1, 2, 3, 4]
// [5, 6, 7, 8]
// [9]
most.iterate(x => x + 1, 0)
  .take(9) // 9 first numbers
  .thru(buffer(4)) // In buffer of 4 or less
  .observe(x => console.log(x))
// Logs
// [1, 2, 3, 4, 5, 6, 7, 8, 9]
most.iterate(x => x + 1, 0)
  .take(9) // 9 first numbers
  .thru(buffer()) // Buffer the complete stream
  .observe(x => console.log(x))

Dependents (12)

Package Sidebar

Install

npm i most-buffer

Weekly Downloads

3

Version

0.0.11

License

BSD-3-Clause

Unpacked Size

3.74 kB

Total Files

5

Last publish

Collaborators

  • craft-ai