New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

simple-chunk-reader

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-chunk-reader

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

  • 1.0.5
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

simple-chunk-reader

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

Install

npm install simple-chunk-reader
yarn add simple-chunk-reader

Usage

const ChunkReader = require("simple-chunk-reader");

const filePath = "./somefile.txt";
const chunkSize = 1024;
const reader = new ChunkReader(filePath, chunkSize);

let content = "";
while (!reader.isDone) {
  content += reader.read();
}

API

The module exports the following functions:

  • constructor
  • read
  • readMultiple
  • closej

constructor

  • new ChunkReader(path: string, size: number): ChunkReader
ParameterTypeDescription
pathstringThe path or location of your file
sizenumberChunk/buffer size in bytes, default: 1024 (1 kB)

read

  • read(): string

It returns a next chunk of current file stream.

Syntax:

const ChunkReader = require("simple-chunk-reader");

const filePath = "./file.txt";
const chunkSize = 8;
const reader = new ChunkReader(filePath, chunkSize);

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

./file.txt

aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooo

Output:

aaaabbbb
ccccdddd
eeeeffff
gggghhhh
iiiijjjj
kkkkllll
mmmmnnnn
oooo

readMultiple

  • readMultiple(total: number): string[]

It returns a next multiple chunk of current file stream.

Syntax:

const ChunkReader = require("simple-chunk-reader");

const filePath = "./file.txt";
const chunkSize = 8;
const reader = new ChunkReader(filePath, chunkSize);

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

./file.txt

aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooo

Output:

['aaaabbbb', 'ccccdddd', 'eeeeffff']
['gggghhhh', 'iiiijjjj', 'kkkkllll']
['mmmmnnnn', '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. read() and readMutiple() will call this function automatically when reaching the end of the stream.

Syntax:

const ChunkReader = require("simple-chunk-reader");

const filePath = "./file.txt";
const chunkSize = 8;
const reader = new ChunkReader(filePath, chunkSize);

console.log(reader.readMultiple(2));
console.log(reader.readMultiple(4));
console.log(reader.read());

reader.close();

./file.txt

aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooo

Output:

['aaaabbbb', 'ccccdddd']
['eeeeffff', 'gggghhhh', 'iiiijjjj', 'kkkkllll']
mmmmnnnn

Keywords

FAQs

Package last updated on 14 Jan 2022

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