graceful-fs-stream
v0.0.1
Published
Graceful filesystem streams.
Downloads
817
Maintainers
Readme
graceful-fs-stream
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
| | |---| | Nicolas Gryman |