rlr
v1.2.0
Published
Read a file in reverse, one line at a time
Downloads
3
Maintainers
Readme
Features
- Zero depedency
- Event-driven
- Full Typescript support
- Supports both ES5 and ES6
Install
$ npm i rlr
Note: This package requires Node >= 14.14.0
Getting Started
import path from 'path';
import Rlr from 'rlr'; // ES6
// const Rlr = require('rlr').default // ES5
const rlr = new Rlr();
const stream = rlr.createInterface(path.resolve('./large-file.txt'))
stream
.on('line', line => console.log(line))
.on('close', () => console.log('end'))
.on('error', err => console.error(err))
// Promise wrapper
const readFileReverse(
file: PathLike,
cb: ((line: string) => void)
) => new Promise<void>((resolve, reject) => new Rlr()
.createInterface(file)
.on('line', cb)
.on('close', resolve)
.on('error', reject));
readFileReverse('./large-file.txt', console.log);
Options
size (default: 65536 (64kb))
Max buffer size in bytesencoding (default: 'utf-8')
File encodingnewline (default: 'os.EOL')
Newline characterignoreEmpty (default: 'true')
Should empty lines be ignored