Thin wrapper for graceful-fs file read stream.
$ npm install flow-readTo create a readStream factory,
varreadStream=require('flow-read'),rStream=readStream();This method is a setter/getter. If no filepath is provided, returns the filepath. You configure the stream factory by specifying a filepath:
rStream.path('path/to/file');Provided a filepath has been specified, to create a new readStream:
varstream=rStream.stream(clbk);Where the optional clbk is invoked upon stream end and has an error as its first argument. If no read errors, error is null.
Methods are chainable:
readStream().path('path/to/file').stream(clbk).pipe(process.stdout);// File read stream generator:varreadStream=require('flow-read');// Create a new stream, passing along an optional error handler:varstream=readStream().path(__dirname+'/path/to/file.json').stream(onError);// Pipe the stream:stream.pipe(process.stdout);// Error handler:functiononError(error){if(error){console.error(error.stack);thrownewError('Error!!!');}console.log('Finished!');}Unit tests use the Mocha test framework with Chai assertions.
Assuming you have installed Mocha, execute the following command in the top-level application directory to run the tests:
$ mochaAll new feature development should have corresponding unit tests to validate correct functionality.
Copyright © 2014. Athan Reines.