0.1.2 • Published 5 years ago
@leadershape/tail v0.1.2
tail
This module allows you tailing file (data by data, line by line and char by char).
Installation
$ npm install @leadershape/Tail
Usage
// Import Tail
import Tail from '@leadershape/Tail'
// Initialize Tail
const tail = new Tail("path/to/file.txt")
// Add listener to line by line processing
tail.on('line', (line) => {
console.log(line)
});
// Start processing
tail.start()
API
Constructor
/**
* Generate an ETag
*
* @param path {string}
* @param options {Options}
*/
Tail(path: string, options?: Options)
Options
/**
* Options
*
* Start reading file from the beginning or the end
* Default: false
* @property {boolean} fromBeginning
*
* Follow keep the Node.js process running and processing new data in file
* Default: true
* @property {boolean} follow
*
* Separator for line processing
* Default: /\r\n|\r|\n/
* @property {string|RegExp} separator
*/
interface Options {
fromBeginning?: boolean;
follow?: boolean;
separator?: string | RegExp;
}
Events
- Data by data
tail.on('data', (data) => {
console.log(data)
})
- Line by line
tail.on('line', (line) => {
console.log("LINE: "+line)
})
- Char by char
tail.on('char', (char) => {
console.log("CHAR:"+char)
})
Start and stop
// Start reading
tail.start();
// Stop
tail.stop();
Testing
$ npm test