Skip to content

Repository files navigation

from-string

NPM versionBuild StatusCoverage StatusDependencies

Converts a string to a readable stream.

Installation

$ npm install flow-from-string

For use in the browser, use browserify.

Usage

To use the module,

varfromString=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,

varstream=fromString('beep');

To set the readable stream options,

varopts={'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.

varopts={'objectMode': true,'encoding': 'utf8','highWaterMark': 8};varfactory=fromString.factory(opts);varstreams=newArray(10),str;// Create many streams configured identically but reading different strings...for(vari=0;i<streams.length;i++){str='';for(varj=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.

varfromString=require('flow-from-string').objectMode;fromString('beep').pipe(process.stdout);

Examples

varappend=require('flow-append').objectMode,fromString=require('flow-from-string');// Create a string...varstr='';for(vari=0;i<200;i++){str+=String.fromCharCode(97+Math.floor(Math.random()*26));}// Create a readable stream:varreadableStream=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

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.

About

Converts a string to a readable stream.

Resources

Stars

2 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages