Simple, buffered, line-by-line file reader with customizable buffer size.

Overview

simple-line-reader

Simple, buffered, line-by-line file reader with customizable buffer size.

Install

npm install simple-line-reader
yarn add simple-line-reader

Usage

const LineReader = require("simple-line-reader");

const reader = new LineReader({
  filePath: "./somefile.txt",
  bufferSize: 1024,
  skipBlank: true,
});

while (!reader.isDone) {
  console.log(reader.nextSingle());
}

API

The module exports the following functions:

constructor

  • new LineReader(options: LineReaderOptions): LineReader
interface LineReaderOptions {
  filePath: string;
  bufferSize?: number; // Defaults to 1024 (1 kB)
  skipBlank?: boolean; // Defaults to false
}

next

  • next(): string[]

It returns a next lines of current file stream.

Syntax:

const LineReader = require("simple-line-reader");

const reader = new LineReader({
  filePath: "./file.txt",
  bufferSize: 10,
});

while (!reader.isDone) {
  console.log(reader.next());
}

./file.txt

aaaa
bbbb
cccc
dddd
eeee
ffff
gggg
hhhh
iiii
jjjj
kkkk
llll
mmmm
nnnn
oooo

Output:

[ 'aaaa', 'bbbb' ]
[ 'cccc', 'dddd' ]
[ 'eeee', 'ffff' ]
[ 'gggg', 'hhhh' ]
[ 'iiii', 'jjjj' ]
[ 'kkkk', 'llll' ]
[ 'mmmm', 'nnnn' ]
[ 'oooo' ]

nextSingle

  • nextSingle(): string

It returns a next single line of current file stream.

Syntax:

const LineReader = require("simple-line-reader");

const reader = new LineReader({
  filePath: "./file.txt",
  bufferSize: 10,
  skipBlank: true,
});

while (!reader.isDone) {
  console.log(reader.nextSingle());
}

./file.txt

aaaa
bbbb
cccc
dddd

eeee
ffff
gggg
hhhh

iiii
jjjj
kkkk
llll
mmmm


nnnn
oooo

Output:

aaaa
bbbb
cccc
dddd
eeee
ffff
gggg
hhhh
iiii
jjjj
kkkk
llll
mmmm
nnnn
oooo

close

  • close(): void

Close the current file descriptor thereby clearing the file stream that is associated with it.

You need to call this method only if you are done before reading the whole content stream. next() and nextSingle() will call this function automatically when reaching the end of the stream.

Syntax:

const LineReader = require("simple-line-reader");

const reader = new LineReader({
  filePath: "./file.txt",
  bufferSize: 10,
  skipBlank: true,
});

console.log(reader.next());
console.log(reader.nextSingle());
console.log(reader.nextSingle());
console.log(reader.next());
console.log(reader.nextSingle());

reader.close();

./file.txt

aaaa
bbbb
cccc
dddd
eeee
ffff
gggg
hhhh
iiii
jjjj
kkkk
llll
mmmm
nnnn
oooo

Output:

[ 'aaaa', 'bbbb' ]
cccc
dddd
[ 'eeee', 'ffff' ]
gggg
[ 'hhhh' ]
You might also like...

This is very simple game catch word with JavaScript and Jquery

Catch-Word-js This is very simple game catch word with JavaScript and Jquery install and run guide! download project zip! extract zip file on any dire

Nov 26, 2022

This is a repository that contains an simple NestJS API about Movies developed at Blue EdTech.

NestJS Movies Technologies and requirements NestJS JavaScript TypeScript Prisma MySQL Project This is a repository that contains an simple NestJS API

Sep 28, 2021

curl for GraphQL with autocomplete, subscriptions and GraphiQL. Also a dead-simple universal javascript GraphQL client.

curl for GraphQL with autocomplete, subscriptions and GraphiQL. Also a dead-simple universal javascript GraphQL client.

graphqurl graphqurl is a curl like CLI for GraphQL. It's features include: CLI for making GraphQL queries. It also provisions queries with autocomplet

Jan 3, 2023

Use Pinata (IPFS) as a simple datastore

🦄 Pinatastore A simple module to store and retrieve simple JSON data from a decentralized databse. (Pinata IPFS) Pinatastore uses a structure similar

Jan 10, 2022

A simple yet powerful discord.js embed pagination package.

A simple yet powerful discord.js embed pagination package.

Pagination.djs A discord.js compatible pagination module. It's a simple and lightweight module to paginate discord embeds. Read docs here: pagination.

Nov 9, 2022

Dead Simple Postgres Data Viewer and Query Runner

Dead Simple Postgres Data Viewer and Query Runner Environment Variables GITHUB_CLIENT_ID Github Client ID of the Oauth Application for protecting your

Aug 22, 2022

Simple CRUD application with Nestjs, Prisma and Docker with Postgres

A progressive Node.js framework for building efficient and scalable server-side applications. Description Nest framework TypeScript starter repository

Nov 6, 2022

PathQL is a json standard based on GraphQL to build simple web applications.

PathQL Usage You can simple create a new PathQL Entry, which allows you to automize database over an orm and client requests over the PathQL JSON Requ

Jul 20, 2022

First NestJS project powered by TypeScript (Simple CRUD)

First Nest TS (TypeScript) First NestJS project powered by TypeScript (Simple CRUD) Routes Get All GET http://localhost:3000/products/ Get one GET htt

Feb 22, 2022
Owner
null
A service worker that buffers a full video, so when the video tag ask for ranges, these can be satisfied. Play + pause = buffer the whole video.

Full Video Buffer with Service Workers The specification of the preload attribute on a Video element won't allow you to fully buffer a video. This rep

Tito 51 Nov 2, 2022
a Node.JS script to auto-import USB drives that are attached to a computer. Use it to turn your NAS into a smart photo / file importer.

File Vacuum 5000 ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ WARNING: This script is designed to manipulate files on both an external drive and another specif

null 46 Jan 10, 2022
A database library stores JSON file for Node.js.

concisedb English | 简体中文 A database library stores JSON file for Node.js. Here is what updated every version if you want to know. API Document Usage B

LKZ烂裤子 3 Sep 4, 2022
A JSON Database that saves your Json data in a file and makes it easy for you to perform CRUD operations.

What is dbcopycat A JSON Database that saves your Json data in a file and makes it easy for you to perform CRUD operations. ⚡️ Abilities Creates the f

İsmail Can Karataş 13 Jan 8, 2023
Fast File is a quick and easy-to-use library to convert data sources to a variety of options.

Fast File Converter The Express.js's Fast File Converter Library Fast File Converter Library is a quick and easy-to-use library to convert data source

Ali Amjad 25 Nov 16, 2022
Display tsc errors count on file tree.

tsc-err-dirs 中文文档 Display tsc errors count on file tree, can hot update when you change those files. Screeshot Requirement node version: >=16 tsc vers

沈青川 87 Nov 18, 2022
Transform stream that lets you peek the first line before deciding how to parse it

streampecker Transform stream that lets you peek the first line before deciding how to parse it

Matteo Collina 12 Jul 7, 2022
A simple Node.js ORM for PostgreSQL, MySQL and SQLite3 built on top of Knex.js

bookshelf.js Bookshelf is a JavaScript ORM for Node.js, built on the Knex SQL query builder. It features both Promise-based and traditional callback i

Bookshelf.js 6.3k Jan 2, 2023
Simple key-value storage with support for multiple backends

Simple key-value storage with support for multiple backends Keyv provides a consistent interface for key-value storage across multiple backends via st

Luke Childs 2k Jan 7, 2023
A simple url shorter API built with nodejs running on Kubernetes in Google Cloud, using PostgreSQL for storage and cloud sql proxy.

Simple URL Shorter - Google Cloud - Kubernetes A simple url shorter API built with nodejs running on Kubernetes in Google Cloud, using PostgreSQL for

null 3 Nov 25, 2021