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

@thi.ng/bitstream

Package Overview
Dependencies
Maintainers
1
Versions
168
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/bitstream

ES6 iterator based read/write bit streams with support for variable word widths

  • 2.2.39
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
148K
decreased by-31.24%
Maintainers
1
Weekly downloads
 
Created

What is @thi.ng/bitstream?

@thi.ng/bitstream is a TypeScript/JavaScript library for working with bit-level data streams. It provides utilities for reading, writing, and manipulating bits in a highly efficient manner. This package is useful for applications that require low-level data processing, such as encoding/decoding, compression, and cryptographic operations.

What are @thi.ng/bitstream's main functionalities?

BitStreamWriter

The BitStreamWriter class allows you to write individual bits or groups of bits to a stream. This is useful for creating custom binary formats or for bit-level data compression.

const { BitStreamWriter } = require('@thi.ng/bitstream');

const writer = new BitStreamWriter();
writer.write(0b101, 3); // write 3 bits
writer.write(0b1111, 4); // write 4 bits
console.log(writer.bytes()); // Uint8Array containing the written bits

BitStreamReader

The BitStreamReader class allows you to read individual bits or groups of bits from a stream. This is useful for parsing custom binary formats or for bit-level data decompression.

const { BitStreamReader } = require('@thi.ng/bitstream');

const reader = new BitStreamReader(new Uint8Array([0b10111100]));
console.log(reader.read(3)); // read 3 bits, output: 5 (0b101)
console.log(reader.read(4)); // read 4 bits, output: 15 (0b1111)

Bit manipulation utilities

The package provides various utility functions for manipulating individual bits within a byte or larger data structure. These functions include setting, clearing, toggling, and getting the value of specific bits.

const { setBit, clearBit, toggleBit, getBit } = require('@thi.ng/bitstream');

let byte = 0b00001111;
byte = setBit(byte, 7); // set the 7th bit, byte becomes 0b10001111
byte = clearBit(byte, 3); // clear the 3rd bit, byte becomes 0b10000111
byte = toggleBit(byte, 0); // toggle the 0th bit, byte becomes 0b10000110
console.log(getBit(byte, 7)); // get the 7th bit, output: 1

Other packages similar to @thi.ng/bitstream

Keywords

FAQs

Package last updated on 28 Dec 2023

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