![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
simple-chunk-reader
Advanced tools
Simple, buffered, chunk-by-chunk file reader with customizable buffer size.
Simple, buffered, chunk-by-chunk file reader with customizable buffer size.
npm install simple-chunk-reader
yarn add simple-chunk-reader
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();
}
The module exports the following functions:
new ChunkReader(path: string, size: number): ChunkReader
Parameter | Type | Description |
---|---|---|
path | string | The path or location of your file |
size | number | Chunk/buffer size in bytes, default: 1024 (1 kB) |
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(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(): 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
FAQs
Simple, buffered, chunk-by-chunk file reader with customizable buffer size.
The npm package simple-chunk-reader receives a total of 0 weekly downloads. As such, simple-chunk-reader popularity was classified as not popular.
We found that simple-chunk-reader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.