Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/borischumichev/node-nthline
Read nth line without reading entire file
https://github.com/borischumichev/node-nthline
node nodejs
Last synced: about 2 months ago
JSON representation
Read nth line without reading entire file
- Host: GitHub
- URL: https://github.com/borischumichev/node-nthline
- Owner: BorisChumichev
- Created: 2017-04-27T19:04:49.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-12-10T17:22:10.000Z (about 5 years ago)
- Last Synced: 2024-11-06T08:53:29.236Z (2 months ago)
- Topics: node, nodejs
- Language: JavaScript
- Size: 10.7 KB
- Stars: 12
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# node-nthline [![Build Status](https://travis-ci.org/BorisChumichev/node-nthline.svg?branch=master)](https://travis-ci.org/BorisChumichev/node-nthline) [![Coverage Status](https://coveralls.io/repos/github/BorisChumichev/node-nthline/badge.svg)](https://coveralls.io/github/BorisChumichev/node-nthline)
`nthline` reads specific line from file without buffering the entire file to memory. Under the hood it uses Node’s [readline](https://nodejs.org/api/readline.html) module.
### Install
```
npm i -S nthline
```### Usage
Module exposes a function with signature: `(rowIndex:Number, filePath:String) → Promise`. Row indexing is zero-based.
```javascript
const nthline = require('nthline'),
filePath = '/path/to/100-million-rows-file',
rowIndex = 42console.log(await nthline(rowIndex, filePath))
```Since it returns a promise you could rewrite previous example like that:
```javascript
const nthline = require('nthline'),
filePath = '/path/to/100-million-rows-file',
rowIndex = 42nthline(rowIndex, filePath).then(console.log)
```