flow-from-string v1.0.1
from-string
Converts a string to a readable stream.
Installation
$ npm install flow-from-stringFor use in the browser, use browserify.
Usage
To use the module,
var fromString = require( 'flow-from-string' );fromString( str, options )
Returns a readable stream where each emitted datum is a character from the input string.
To convert a string to a readable stream,
var stream = fromString( 'beep' );To set the readable stream options,
var opts = {
'objectMode': true,
'encoding': 'utf8',
'highWaterMark': 8
};
stream = fromString( 'beep', opts );fromString.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 = fromString.factory( opts );
var streams = new Array( 10 ),
str;
// Create many streams configured identically but reading different strings...
for ( var i = 0; i < streams.length; i++ ) {
str = '';
for ( var j = 0; j < 100; j++ ) {
str += String.fromCharCode(97 + Math.floor(Math.random() * 26));
}
streams[ i ] = factory( str );
}fromString.objectMode( str, 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 fromString = require( 'flow-from-string' ).objectMode;
fromString( 'beep' )
.pipe( process.stdout );Examples
var append = require( 'flow-append' ).objectMode,
fromString = require( 'flow-from-string' );
// Create a string...
var str = '';
for ( var i = 0; i < 200; i++ ) {
str += String.fromCharCode(97 + Math.floor(Math.random() * 26));
}
// Create a readable stream:
var readableStream = fromString( str );
// Pipe the data:
readableStream
.pipe( append( '\n' ) )
.pipe( process.stdout );To run the example code from the top-level application directory,
$ node ./examples/index.jsTests
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 testAll 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-covIstanbul creates a ./reports/coverage directory. To access an HTML version of the report,
$ open reports/coverage/lcov-report/index.htmlLicense
Copyright
Copyright © 2014. Athan Reines.