1.0.2 • Published 5 years ago

nthline v1.0.2

Weekly downloads
1,027
License
MIT
Repository
github
Last release
5 years ago

node-nthline Build Status Coverage Status

nthline reads specific line from file without buffering the entire file to memory. Under the hood it uses Node’s readline module.

Install

npm i -S nthline

Usage

Module exposes just one function: nthline with signature: (rowIndex:Number, filePath:String) → Promise. Row indexing is zero-based.

;(async () => {
  const nthline = require('nthline'),
    filePath = '/path/to/100-million-rows-file',
    rowIndex = 42

  console.log(await nthline(rowIndex, filePath))
})()

Since it returns a promise you could rewrite previous example like that:

const nthline = require('nthline'),
  filePath = '/path/to/100-million-rows-file',
  rowIndex = 42

nthline(rowIndex, filePath).then(line => console.log(line))