Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

strtok3

Package Overview
Dependencies
Maintainers
1
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

strtok3

A promise based streaming tokenizer

  • 10.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.2M
increased by4.76%
Maintainers
1
Weekly downloads
 
Created

What is strtok3?

The strtok3 npm package is a streaming tokenizer for Buffer and string inputs in Node.js. It allows developers to parse through binary data or strings efficiently by defining tokenizers that can extract pieces of data sequentially. This is particularly useful for reading binary files or network streams where data structures are defined in terms of sequences or patterns of bytes.

What are strtok3's main functionalities?

Tokenizing fixed-length binary data

This feature allows for reading fixed-length binary data from a file. The example demonstrates reading a 32-bit unsigned integer from the beginning of a file.

const strtok3 = require('strtok3');
const { token } = require('strtok3/core');

async function parseBinaryFile(filePath) {
  const tokenizer = await strtok3.fromFile(filePath);
  const header = await tokenizer.readToken(token.UINT32_LE);
  console.log('Header:', header);
}

Tokenizing a stream of data

This feature is used for tokenizing data directly from a stream. The example shows how to read a size as a 32-bit unsigned integer and then read a buffer of that size from the stream.

const strtok3 = require('strtok3');
const { token } = require('strtok3/core');
const fs = require('fs');

const stream = fs.createReadStream('path/to/file');
const tokenizer = strtok3.fromStream(stream);

async function readData() {
  const size = await tokenizer.readToken(token.UINT32_LE);
  const data = await tokenizer.readToken(new token.BufferType(size));
  console.log('Data:', data.toString());
}

Other packages similar to strtok3

Keywords

FAQs

Package last updated on 30 Nov 2024

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