🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

readtoken

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

readtoken

Read file token by token

0.0.3
latest
Source
npm
Version published
Weekly downloads
6.6K
25.55%
Maintainers
1
Weekly downloads
 
Created
Source

readtoken

readtoken allows you to read file token by token.

How to use it is similar to readline.

You can get token by token event. And you can detect EOF by close event.

Currently supported events are only above two.

Install

npm install readtoken

How to use

The constructor of ReadToken class takes 2 arguments.

  • 1st. Readable stream. required.
  • 2nd. options object. optional.
const fs = require("fs");
const ReadToken = require("readtoken");

const is = fs.createReadStream("test/data/simple1.txt", {
  encoding: 'utf8'
});
const tokens = [];
const readToken = new ReadToken(is);
  maxLength: 5
});
readToken.on("token", (token) => {
  tokens.push(token);
});
readToken.on("close", () => {
  console.log(tokens);
});

options

  • sep: string
    • separator characters.
    • default: `" \t\r\n"
  • maxLength: number
    • The max length of each tokens. If token in file is longer than this value, it will be sliced by this number.
    • default: 0. 0 means it doesn't have maxLength.
  • readSize: number
    • read buffer size
    • default: 8192

Keywords

nodejs

FAQs

Package last updated on 26 Feb 2019

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