# line-by-line

> A NodeJS module that helps you reading large text files, line by line, without buffering the files into memory.

Latest version **0.1.6** (published 2017-12-26) · 0 weekly downloads

## Install

```sh
npm install line-by-line
pnpm add line-by-line
yarn add line-by-line
bun add line-by-line
```

## Health

**Score 18/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2017-12-26 |
| First published | 2012-10-17 |
| Weekly downloads | 0 |
| TypeScript types | separate (@types/line-by-line) |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 142 |
| Author | Markus Ostertag |
| Maintainers | osterjour |
| Keywords | line, file, reader, fs |

## Links

- npm: https://www.npmjs.com/package/line-by-line
- Repository: https://github.com/Osterjour/line-by-line
- Issues: https://github.com/Osterjour/line-by-line/issues
- npm.io page: https://npm.io/package/line-by-line

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 0.1.6 (latest) — 2017-12-26
- 0.1.5 — 2016-06-30
- 0.1.4 — 2015-08-19
- 0.1.3 — 2014-11-01
- 0.1.2 — 2014-11-01
- 0.1.1 — 2012-10-17
- 0.1.0 — 2012-10-17

## README

[![Build Status](https://travis-ci.org/Osterjour/line-by-line.svg?branch=master)](https://travis-ci.org/Osterjour/line-by-line)
[![npm version](https://badge.fury.io/js/line-by-line.svg)](http://badge.fury.io/js/line-by-line)

# Line By Line
is a [NodeJS](http://nodejs.org/) module
that helps you reading large text files, line by line,
without buffering the files into memory.

Installation:

    npm install line-by-line


## Usage:

Synchronous processing of lines:

	var LineByLineReader = require('line-by-line'),
	    lr = new LineByLineReader('big_file.txt');

	lr.on('error', function (err) {
		// 'err' contains error object
	});

	lr.on('line', function (line) {
		// 'line' contains the current line without the trailing newline character.
	});

	lr.on('end', function () {
		// All lines are read, file is closed now.
	});

Asynchronous processing of lines:

	var LineByLineReader = require('line-by-line'),
	    lr = new LineByLineReader('big_file.txt');

	lr.on('error', function (err) {
		// 'err' contains error object
	});

	lr.on('line', function (line) {
		// pause emitting of lines...
		lr.pause();

		// ...do your asynchronous line processing..
		setTimeout(function () {

			// ...and continue emitting lines.
			lr.resume();
		}, 100);
	});

	lr.on('end', function () {
		// All lines are read, file is closed now.
	});
	
Initialize with Stream:

    var LineByLineReader = require('line-by-line'),
	    lr = new LineByLineReader(S3.getObject({ Bucket, Key }).createReadStream());

## API:

**Class: LineReader(path [, options])**

`path` specifies the file to read or Stream

`options` is an object with the following defaults:
```
{ encoding: 'utf8',
  skipEmptyLines: false }
```

`encoding` can be `'utf8'`, `'ascii'`, or `'base64'`.

If `skipEmptyLines` set to `true`, empty lines don't trigger a 'line' event.

You can also pass `start` and `end` position in bytes to read from file region:

```
{ encoding: 'utf8',
  skipEmptyLines: true,
  start: 1000 }
```


**Event: 'line'**

    function (line) { }

Emitted on every line read.

`line` contains the line without the line ending character.


**Event: 'error'**

    function (error) { }

Emitted if an error occurred.

`error` contains the error object.


**Event: 'end'**

    function () { }

Emitted if all lines are read.


**pause()**

Call this method to stop emitting 'line' events.


**resume()**

After calling this method, 'line' events gets emitted again.


**close()**

Stops emitting 'line' events, closes the file and emits the 'end' event.


## License:

The MIT License (MIT)

Copyright © 2012 Markus von der Wehd

---
_Source: https://npm.io/package/line-by-line · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
