Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alsotang/co-readline
Read a file line by line in generator/co style
https://github.com/alsotang/co-readline
Last synced: 13 days ago
JSON representation
Read a file line by line in generator/co style
- Host: GitHub
- URL: https://github.com/alsotang/co-readline
- Owner: alsotang
- Created: 2016-12-02T07:58:40.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-07T03:49:18.000Z (about 8 years ago)
- Last Synced: 2024-12-03T19:37:58.950Z (about 1 month ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# co-readline
[![Build Status](https://travis-ci.org/alsotang/co-readline.svg?branch=master)](https://travis-ci.org/alsotang/co-readline)
[![codecov](https://codecov.io/gh/alsotang/co-readline/branch/master/graph/badge.svg)](https://codecov.io/gh/alsotang/co-readline)
Read a file line by line in generator/co style.
## install
`$ npm i co-readline`
## easy example
```js
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