graceful-fs-stream

0.0.1 • Public • Published

graceful-fs-stream

NPM Build Status Dependency Status Gittip


Graceful filesystem streams.

Provides both readable and writable filesystem streams that open the file on first read or write.

Because stream producers are not always stream consumers, it can be useful to create a stream without worrying if data has ever been read or written. It lazy opens or creates files. So it ensures a loose coupling between stream creation and file opening or creation. This can be useful in various use case where you can to create streams without accessing the file system yet.

Installation

npm install graceful-fs-stream --production

Usage

var fs = require('graceful-fs-stream');
 
/** read stream */
 
var readable = fs.createReadStream(file);
// file is no yet open
readable.once('data', function() {
    // file was just open
});
 
/** write stream */
 
var writable = fs.createWriteStream(path);
// file is not yet open
writable.write('hey');
// file was just open

Note that if you try to close a stream directly, it won't crash badly.

Author

twitter/ngryman
Nicolas Gryman

Package Sidebar

Install

npm i graceful-fs-stream

Weekly Downloads

209

Version

0.0.1

License

MIT

Last publish

Collaborators

  • ngryman