co-readable
v1.0.1
Published
Easy way to read stream data with co
Downloads
2
Maintainers
Readme
co-readable
Easy way to read stream data with co.
Install
$ npm i co-readable
Usage
readable(stream)
Read a stream data buffer piece by piece.
const fs = require('fs');
const readable = require('co-readable');
const co = require('co');
const read = readable(fs.createReadStream('bigfile'));
co(function* () {
let buf;
let size = 0;
while (buf = yield read(1024)) {
console.log('read %d bytes', buf.length);
size += buf.length;
}
console.log('total read %d bytes', size);
}).catch(function (err) {
console.error(err.stack);
});
readable.readAll(stream)
Read all data into one buffer.
const fs = require('fs');
const readable = require('co-readable');
const co = require('co');
co(function* () {
const buf = yield readable.readAll(fs.createReadStream('bigfile'));
console.log('total read %d bytes', buf.length);
}).catch(function (err) {
console.error(err.stack);
});