0.1.5 • Published 5 years ago

tru_readfile v0.1.5

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

tru_readfile

A node module that reads a file line by line.

  • Start your task with a an array of all the lines
  • Run async tasks on each line then resume the job

License

ISC

Installation

npm install tru_readfile --save
// or
yarn add tru_readfile

build source with tsc

Usage

Javascript

var ReadFile = require('tru_readfile');

// get all lines
new ReadFile({
    path: 'myFile.txt',
    onSuccess: function(lines) {
        console.log(lines);
    },
    onError: function(err) {
        throw err;
    }
});

// or perform an async task on each line then resume file loading
new ReadFile({
    path: 'myFile.txt',
    onLine: function(line, resume) {

        // async task
        setTimeout(function() {
            console.log('new line: '+line);
            resume(); // do not forget to resume
        }, 1000);
    },
    onSuccess: function() {
        console.log('end of file');
    },
    onError: function(err) {
        throw err;
    }
});

TypeScript

import ReadFile from 'tru_readfile';

// get all lines
new ReadFile({
    path: 'myFile.txt',
    onSuccess: (lines: string[]) => {
        console.log(lines);
    },
    onError: (err: ErrorEvent) => {
        throw err;
    }
});

// or perform an async task on each line then resume file loading
new ReadFile({
    path: 'myFile.txt',
    onLine: (line: string, resume(): void) => {

        // async task
        setTimeout(() => {
            console.log('new line: '+line);
            resume(); // do not forget to resume
        }, 1000);
    },
    onSuccess: () => {
        console.log('end of file');
    },
    onError: (err: ErrorEvent) => {
        throw err;
    }
});
0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago