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

line-reader

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

line-reader

Asynchronous, buffered, line-by-line file/stream reader

  • 0.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
134K
increased by0.87%
Maintainers
1
Weekly downloads
 
Created

What is line-reader?

The line-reader npm package is a simple utility for reading lines from a readable stream one at a time. It is particularly useful for processing large files line by line without loading the entire file into memory.

What are line-reader's main functionalities?

Reading lines synchronously

This feature allows you to read lines from a file synchronously. The `eachLine` method reads each line of the file and executes a callback function for each line. The callback receives the line content and a boolean indicating if it is the last line.

const lineReader = require('line-reader');

lineReader.eachLine('file.txt', function(line, last) {
  console.log(line);
  if (last) {
    console.log('End of file reached');
  }
});

Reading lines asynchronously

This feature allows you to read lines from a file asynchronously. The `open` method opens the file and provides a reader object. The reader object has methods like `hasNextLine` and `nextLine` to read lines asynchronously.

const lineReader = require('line-reader');

lineReader.open('file.txt', function(reader) {
  if (reader.hasNextLine()) {
    reader.nextLine(function(line) {
      console.log(line);
    });
  }
});

Reading lines with promises

This feature allows you to read lines using promises. By using Node.js's `util.promisify`, you can convert the callback-based `eachLine` method into a promise-based one, making it easier to work with async/await.

const lineReader = require('line-reader');
const { promisify } = require('util');

const eachLine = promisify(lineReader.eachLine);

async function readLines() {
  await eachLine('file.txt', function(line) {
    console.log(line);
  });
}

readLines();

Other packages similar to line-reader

Keywords

FAQs

Package last updated on 17 Mar 2016

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