Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mmis1000/readlines

a multiline and non-flow implement for nodejs readline
https://github.com/mmis1000/readlines

Last synced: 9 days ago
JSON representation

a multiline and non-flow implement for nodejs readline

Awesome Lists containing this project

README

        

Read big files or streams with better memory usage.
This currently only works with streams in non-flow mode.

###usage

readlines = require ("lines-reader")
reader = new readlines(options)

###options

fileName :
absolute / relative file path [optional]
actully remapped to your call location,
so use relative path to current file will work
input : streams [ignored if fileName was set, required]
output : streams [optional]
lines : number [prefetch lines before readable event was emited, default to 10]
preloadLinesRatio : number [a multifier for lines option, default to 2]
ignoreEmptyLine : boolean [ignore 0 byte lines, default to true]
macStyleLineEnd : boolean [use \r instead of \r?\n as line separator, default to false]
encode : null/string [output encode, default to null(buffer)]
maxBuffer : number [flush lines immediately if output buffer excceed this, default to lines * 256]

###event

line : emit when new line, listen to this cause reader turn into flow mode
readable : emit when enough lines were prefetched
end : emit when source was closed and internal buffer flushed

###example(flowMode)

readlines = require "lines-reader"
reader = new readlines({fileName : "../package.json", encode : "utf8"})
reader.on 'line', (line)->
console.log line
reader.pause()
setTimeout (()->
reader.resume()
), 1000
#print text with delay of each line

example(non-flowMode)

readlines = require "lines-reader"
reader = new readlines({fileName : "../package.json", encode : "utf8"})
reader.once 'readable', ()->
read = ()->
line = reader.readline()
if line
console.log line
if !reader.exited
setTimeout read, 1000
read()