npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

query-lines-reader

v0.2.3

Published

Query multi lines by reading file. Support big file for nodejs

Readme

query-lines-reader

Query multi lines or pagination by reading file. Support big file for nodejs

Install

$ npm install query-lines-reader

中文文档

Usage

General usage


let queryLinesReader = new QueryLinesReader(filePath, options);

queryLinesReader.queryLines(options).then(lineRes => {});

queryLinesReader.getTotal().then(totalRes => {});

You can use the api set a file size. The ‘fileSize‘ for different decisions to improve efficiency

We use ‘readline’ module to read the file when less than then the size We use system command to get file info when greater than the size default 1.5 * 1024 K


let queryLinesReader = new QueryLinesReader(filePath, options);

queryLinesReader.setMinSizeOfCommand(fileSize)

Options

filePath

  1. File absolute path, example: path.resolve(__dirname, './test.txt')

  2. Stream, the stream path is must be absolute, example: fs.createReadStream(path.resolve(__dirname, './test.txt'))

  3. Buffer, example: Buffer.from(path.resolve(__dirname, './test.txt'))

  4. URL, example: new URL('file:///tmp/hello')

options

start && end:

  • Type: Number
  • start: you need first line number (Default 0)
  • end: you need last line number (Default 10)

the line include start exclude end. [start, end) !!!!

pageSize && currentPage

  • Type: Number
  • pageSize: number of pages per page (Default 10)
  • currentPage: current page (Default 0)

needTotal

  • Type: Boolean
  • If true will return total lines or not

reverse

  • Type: Boolean, read direction
  • Tf false, from top to bottom
  • If true, from bottom to top

include

  • Type: String or RegExp, string or regular expression
  • You can use it to search file

lineRes

  • lineList: lines result
  • total: if options.needTotal is true, this will return

totalRes

  • Type: Number, file's total line

Example

// From top to bottom
const path = require('path');
const QueryLinesReader = require('query-lines-reader');

let queryLinesReader = new QueryLinesReader(path.resolve(__dirname, './test.txt'));

queryLinesReader.queryLines({
    start: 0,
    end: 2
}).then(res => {
    res.lineList // ['xx', 'xxxx']
})
// From bottom to top
const path = require('path');
const QueryLinesReader = require('query-lines-reader');

let queryLinesReader = new QueryLinesReader(path.resolve(__dirname, './test.txt'), {
    reverse: true,
    // include: /xxxx/g
});

queryLinesReader.queryLines({
    start: 0,
    end: 2,
    // reverse: true     // You can also set it here
    // include: /xxxx/g  // You can also set it here
}).then(res => {
    res.lineList // ['xxxx', 'xx']
})
// Pagination
const path = require('path');
const QueryLinesReader = require('query-lines-reader');

let queryLinesReader = new QueryLinesReader(path.resolve(__dirname, './test.txt'), {
    pageSize: 10
});

// first page
queryLinesReader.queryLines({
    currentPage: 0
}).then(res => {
    res.lineList // ['xx', 'xxxx', ...]
});

// third page
queryLinesReader.queryLines({
    currentPage: 2
}).then(res => {
    res.lineList // ['xx', 'xxxx', ...]
});

Others

This api is global api, set process‘s maximum of one cpu. If the maximum number is exceeded, a another strategy of reader will be used

QueryLinesReader.setProcessNumberOfSingleCpu(2);

query-lines-reader

高效分页、按行读取文件,支持大文件

安装

$ npm install query-lines-reader

使用

一般用法


let queryLinesReader = new QueryLinesReader(filePath, options);

queryLinesReader.queryLines(options).then(lineRes => {});

queryLinesReader.getTotal().then(totalRes => {});

setMinSizeOfCommand 这个 API 是设置文件大小的一个值,用不同策略来提高效率

小于这个值的时候,我们用 ‘readline’ 这个模块来读取文件 大于这个值的时候,我们使用 系统内部命令 读取文件 默认是 1.5 * 1024 k


let queryLinesReader = new QueryLinesReader(filePath, options);

queryLinesReader.setMinSizeOfCommand(fileSize)

参数

filePath

  1. 文件的绝对路径,例如: path.resolve(__dirname, './test.txt')

  2. stream 流, 流的路径也必须是绝对路径, 例如: fs.createReadStream(path.resolve(__dirname, './test.txt'))

  3. Buffer, 例如: Buffer.from(path.resolve(__dirname, './test.txt'))

  4. URL, 例如: new URL('file:///tmp/hello')

options

start && end:

  • 类型: Number
  • start: 读取的第一行的行数 (Default 0)
  • end: 读取的最后一行 (Default 10)

读取结果 包含 start 不包含 end. [start, end) !!!!

pageSize && currentPage

  • 类型: Number
  • pageSize: 每页的数量 (Default 10)
  • currentPage: 当前页 (Default 0)

needTotal

  • 类型: Boolean
  • 如果你设置它为 true 会返回总数

reverse

  • 类型: Boolean, 文件读取方向
  • 如果是 false, 从上往下读
  • 如果是 true, 从下往上读

include

  • 类型: String or RegExp, 包含的字符串或者正则表达式
  • 可以使用这个值去搜索文件

lineRes

  • lineList: 读取文件的结果
  • total: 如果 options.needTotal 是 true, 将会返回这个值

totalRes

  • 类型: Number, 文件的总行数

例子

// 从上往下读
const path = require('path');
const QueryLinesReader = require('query-lines-reader');

let queryLinesReader = new QueryLinesReader(path.resolve(__dirname, './test.txt'));

queryLinesReader.queryLines({
    start: 0,
    end: 2
}).then(res => {
    res.lineList // ['xx', 'xxxx']
})
// 从下往上读
const path = require('path');
const QueryLinesReader = require('query-lines-reader');

let queryLinesReader = new QueryLinesReader(path.resolve(__dirname, './test.txt'), {
    reverse: true,
    // include: /xxxx/g
});

queryLinesReader.queryLines({
    start: 0,
    end: 2,
    // reverse: true     // 你也能在这里设置它
    // include: /xxxx/g  // 你也能在这里设置它
}).then(res => {
    res.lineList // ['xxxx', 'xx']
})
// 分页
const path = require('path');
const QueryLinesReader = require('query-lines-reader');

let queryLinesReader = new QueryLinesReader(path.resolve(__dirname, './test.txt'), {
    pageSize: 10
});

// 第一页
queryLinesReader.queryLines({
    currentPage: 0
}).then(res => {
    res.lineList // ['xx', 'xxxx', ...]
});

// 第三页
queryLinesReader.queryLines({
    currentPage: 2
}).then(res => {
    res.lineList // ['xx', 'xxxx', ...]
});

Others

这个是全局 api, 并发较大时一个 cpu 可以开两个子进程。当进程数都占满后 会通过 ‘readline’ 模块去读文件。

QueryLinesReader.setProcessNumberOfSingleCpu(2);