file-line-scanner
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

File Line Scanner

Utility class for analyzing a file and counting lines in it. After analyzing you can read lines from the line with simple from -> to syntax.

Tested with UTF-8 text files. Other files behaviour is unknown.

Usage

import FileLineScanner from 'file-line-scanner';

const examplePath = '/var/logs/log.txt';


async main() {
    const scanner = new FileLineScanner(examplePath);
    // Scanner needs to be started before lines can be fetched.
    await scanner.start();
    // File has been analyzed
    // Line count
    console.log(scanner.lineCount);
    // Lines start from 0
    // Get lines from 1 to 100 (excludes the 101st line, you will end up with lines from 1 - 100);
    console.log(await scanner.getLines(0, 100));
}

Options

// Pass options to the FileLineScanner constructor's last argument
new FileLineScanner(path, opts: {
    encoding?: string; // BufferEnconding same encodings as supported by Buffer
    skipLastLine?: boolean; // If true last line of the file will be skipped when reading lines
})

Package Sidebar

Install

npm i file-line-scanner

Weekly Downloads

5

Version

1.0.3

License

MIT

Unpacked Size

19.7 kB

Total Files

11

Last publish

Collaborators

  • tvieno