1.2.2 • Published 7 years ago

co-readline v1.2.2

Weekly downloads
24
License
MIT
Repository
github
Last release
7 years ago

co-readline

Build Status

codecov

Read a file line by line in generator/co style.

install

$ npm i co-readline

easy example

var coReadline = require('co-readline')
var co = require('co')

co(function * () {
  var NORMAL_FILE_PATH = 'absolute_path_to_file'
  var rlGen = coReadline(NORMAL_FILE_PATH)

  var lines = []

  for (var line of rlGen) {
    if (line.then) { // `line` could be Promise or String
      line = yield line;
    }

    lines.push(line)
  }

  var fileContent = yield fs.readFile(NORMAL_FILE_PATH, 'utf-8')
  fileContent.should.equal(lines.join('\n'))
})

api

coReadline(filePath) return a generator, then do for..of to it

benchmark

About 1/3 speed of build-in readline module

About 1/6 speed of fs.readFileSync

Read about 1 million lines per second

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

0.0.1

7 years ago