New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
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
  • Socket score

Version published
Weekly downloads
3.2K
decreased by-47.12%
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

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

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