Converts a string to a readable stream.
$ npm install flow-from-string
For use in the browser, use browserify.
To use the module,
var fromString = require( 'flow-from-string' );
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 );
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 );
}
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 );
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.js
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.
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
Copyright © 2014. Athan Reines.