flow-read-array

1.1.1 • Public • Published

read-array

NPM version Build Status Coverage Status Dependencies

Converts an array to a readable stream.

DEPRECATED: use flow-from-array.

Installation

$ npm install flow-read-array

For use in the browser, use browserify.

Usage

To use the module,

var readArray = require( 'flow-read-array' );

readArray( arr[, options] )

Returns a readable stream where each emitted datum is an element from the input array.

To convert an array to a readable stream,

var stream = readArray( [1,2,3,4] );

To set the readable stream options,

var opts = {
        'objectMode': true,
        'encoding': 'utf8',
        'highWaterMark': 8
    };
 
stream = readArray( ['b','e','e','p'], opts );

readArray.factory( [options] )

Returns a reusable stream factory. The factory method ensures streams are configured identically by using the same set of provided options.

var opts = {
        'objectMode': true,
        'encoding': 'utf8',
        'highWaterMark': 8
    };
 
var factory = readArray.factory( opts );
 
var streams = new Array( 10 ),
    data;
 
// Create many streams configured identically but reading different datasets...
for ( var i = 0; i < streams.length; i++ ) {
    data = new Array( 100 );
    for ( var j = 0; j < data.length; j++ ) {
        data[ j ] = Math.random();
    }
    streams[ i ] = factory( data );
}

readArray.objectMode( arr[, options] )

This method is a convenience function to create readable streams which always operate in objectMode. The method will always override the objectMode option in options.

var readArray = require( 'flow-read-array' ).objectMode;
 
readArray( ['b','e','e','p'] )
    .pipe( process.stdout );

Examples

var toString = require( 'flow-to-string' ),
    append = require( 'flow-append' ).objectMode,
    readArray = require( 'flow-read-array' );
 
// Create some data...
var data = new Array( 1000 );
for ( var i = 0; i < data.length; i++ ) {
    data[ i ] = Math.random();
}
 
// Create a readable stream:
var readStream = readArray( data );
 
// Pipe the data:
readStream
    .pipe( toString() )
    .pipe( append( '\n' ) )
    .pipe( process.stdout );

To run the example code from the top-level application directory,

$ node ./examples/index.js

Notes

This stream is a Streams2 version of event-stream and its readArray() method.

Tests

Unit

Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:

$ make test

All new feature development should have corresponding unit tests to validate correct functionality.

Test Coverage

This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

$ make test-cov

Istanbul creates a ./reports/coverage directory. To access an HTML version of the report,

$ open reports/coverage/lcov-report/index.html

License

MIT license.


Copyright

Copyright © 2014. Athan Reines.

Package Sidebar

Install

npm i flow-read-array

Weekly Downloads

0

Version

1.1.1

License

none

Last publish

Collaborators

  • kgryte