1.1.2 • Published 10 years ago

lines-reader v1.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

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()
1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago