Skip to content

Latest commit

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

flow-write

Thin wrapper for graceful-fs file write stream.

Installation

$ npm install flow-write

API

To create a writeStream factory,

varwriteStream=require('flow-write'),wStream=writeStream();

wStream.path( [filepath] )

This method is a setter/getter. If no output filepath is provided, returns the output filepath. You configure the stream factory by specifying an output filepath:

wStream.path('path/to/output/destination');

wStream.stream( [clbk] )

Provided a filepath has been specified, to create a new writeStream:

varstream=wStream.stream(clbk);

Where the optional clbk is invoked upon stream end and has an error as its first argument. If no write errors, error is null.

Usage

Methods are chainable:

varstream=writeStream().path('path/to/file/destination').stream(clbk);readStream.pipe(stream);

Examples

vareventStream=require('event-stream'),writeStream=require('flow-write');// Create some data...vardata=newArray(1000);for(vari=0;i<data.length;i++){data[i]=Math.random();}// Create a readable stream:varreadStream=eventStream.readArray(data);// Create a new stream, passing along an optional error handler:varstream=writeStream().path(__dirname+'/path/to/output/file.json').stream(onError);// Pipe the data to the stream...readStream.pipe(stream);// Error handler:functiononError(error){if(error){console.error(error.stack);thrownewError('Error!!!');}console.log('Finished!');}

Tests

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:

$ mocha

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

License

MIT license.


Copyright

Copyright © 2014. Athan Reines.

About

Thin wrapper for (graceful-fs) file write stream.

Resources

Stars

1 star

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages