Skip to content

cojs/readable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

co-readable

NPM version build status Test coverage Gittip David deps npm download

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);
});

License

MIT