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

bit-buffer

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bit-buffer

Bit-level reads and writes for ArrayBuffers

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.6K
increased by51.93%
Maintainers
1
Weekly downloads
 
Created
Source

BitBuffer

BitBuffer provides two objects, BitView and BitStream. BitView is a wrapper for ArrayBuffers, similar to JavaScript's DataView, but with support for bit-level reads and writes. BitStream is a wrapper for a BitView used to help maintain your current buffer position, as well as to provide higher-level read / write operations such as for ASCII strings.

BitView

Attributes

bb.buffer  // Underlying ArrayBuffer.

Methods

BitView(buffer, optional byteOffset, optional byteLength)

Default constructor, takes in a single argument of an ArrayBuffer. Optional are the byteOffset and byteLength arguments to offset and truncate the view's representation of the buffer.

getBits(offset, bits, signed)

Reads bits number of bits starting at offset, twiddling the bits appropriately to return a proper 32-bit signed or unsigned value. NOTE: While JavaScript numbers are 64-bit floating-point values, we don't bother with anything other than the first 32 bits.

getInt8, getUint8, getInt16, getUint16, getInt32, getUint32(offset)

Shortcuts for getBits, setting the correct bits / signed values.

getFloat32(offset)

Gets 32 bits from offset, and coerces and returns as a proper float32 value.

getFloat64(offset)

Gets 64 bits from offset, and coerces and returns as a proper float64 value.

setBits(offset, value, bits)

Sets bits number of bits at offset.

setInt8, setUint8, setInt16, setUint16, setInt32, setUint32(offset)

Shortcuts for setBits, setting the correct bits count.

setFloat32(offset)

Coerces a float32 to uint32 and sets at offset.

setFloat64(offset)

Coerces a float64 to two uint32s and sets at offset.

BitStream

Attributes

bb.byteIndex  // Get current index in bytes.
bb.byteIndex = 0;  // Set current index in bytes.
bb.view  // Underlying BitView

Methods

BitStream(view)

Default constructor, takes in a single argument of a BitView.

BitSteam(buffer, optional byteOffset, optional byteLength)

Shortcut constructor that initializes a new BitView(buffer, byteOffset, byteLength) for the stream to use.

readBits(bits, signed)

Returns bits numbers of bits from the view at the current index, updating the index.

writeBits(value, bits)

Sets bits numbers of bits from value in the view at the current index, updating the index.

readASCIIString(optional bytes)

Reads bytes from the underlying view at the current index until either bytes count is reached or a 0x00 terminator is reached.

writeASCIIString(string, optional bytes)

Writes a string followed by a NULL character to the underlying view starting at the current index. If the string is longer than bytes it will be truncated, and if it is shorter 0x00 will be written in its place.

Keywords

FAQs

Package last updated on 12 Aug 2013

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