Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

line-by-line

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

line-by-line

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

  • 0.1.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
30K
decreased by-24.98%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status npm version

Line By Line

is a NodeJS 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

Keywords

FAQs

Package last updated on 26 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc