line-chomper
Chomps utf-8 based byte stream into lines.
- Interactive line processing (callback-based, no loading the entire file into RAM)
- Optionally, return all lines in an array (detailed or raw mode)
- Interactively interrupt streaming, or perform map/filter like processing
- Detect any newline convention (PC/Mac/Linux)
- Correct eof / last line treatment
- Correct handling of multi-byte UTF-8 characters
- Retrieve byte offset and byte length information on per-line basis
- Random access, using line-based or byte-based offsets
- Automatically map line-offset information, to speed up random access
- Zero dependencies
- Tests
Basic usage
var chomp = chomp; ;
Interactive processing
;});
Process arbitrary stream
var req = http; req; req;
Map / filter using lineCallback
var counter = 0;;});
Random access based on line numbers (also can accept byte offsets)
;
Map line offsets to speed up random access in large files
; // later... { redis;}
For more usage examples, check out the spec folder.
Options
All options with defaults and helpful comments can be seen here.
FAQ
Q: Why another line splitter library?
A: I was frustrated with other libraries being
- too old / outdated
- nice but (I hear) buggy
- lacking advanced options for random access that I need for my project
Q: Why the name '*-chomper'? That word doesn't mean what you think it means
A: All the good, obvious names were taken
Q: What's next?
A: Probably a slow decline into the maintenance mode, unless there is pressing need to expand. Bug fixes are always welcome. Also, I might add an advanced asynchronous chunk-by-chunk processing mode, suitable for handling large files with progress reports, buffered DB access and such. TL;DR:
- Bug fixes
- Maybe a new feature or two
- Profit
Update log
Date | Version | Description |
---|---|---|
2015-05-06 | 0.5.0 | Added lineCallback argument to mapLineOffsets() |
Licence
Apache v2. I'm told it's nice and fluffy. Read it here.