bitfield

  • Version 5.0.1
  • Published
  • 24.7 kB
  • No dependencies
  • MIT license

Install

npm i bitfield
yarn add bitfield
pnpm add bitfield

Overview

a simple bitfield, compliant with the BitTorrent spec

Index

Classes

class BitField

class BitField {}
  • Bit-level set/get utility backed by a growable Uint8Array.

constructor

constructor(data?: number | Uint8Array, options?: BitFieldOptions);
  • Constructs a BitField.

    Parameter data

    Either a number representing the maximum number of supported bits, or a Uint8Array.

    Parameter options

    Configuration for bitfield growth behavior.

property buffer

buffer: Uint8Array;
  • The internal storage of the bitfield.

property length

readonly length: number;
  • The number of bits in the bitfield.

method forEach

forEach: (
callbackfn: (bit: boolean, index: number) => void,
start?: number,
end?: number
) => void;
  • Loop through the bits in the bitfield.

    Parameter callbackfn

    Function to be called with the bit value and index.

    Parameter start

    Index of the first bit to look at.

    Parameter end

    Index of the first bit that should no longer be considered.

method get

get: (bitIndex: number) => boolean;
  • Get a particular bit.

    Parameter bitIndex

    Bit index to retrieve.

    Returns

    A boolean indicating whether the ith bit is set.

method isEmpty

isEmpty: () => boolean;
  • Check if all bits in the Bitfield are unset.

    Returns

    A boolean indicating whether all bits are unset.

method set

set: (bitIndex: number, value?: boolean) => void;
  • Set a particular bit.

    Will grow the underlying array if the bit is out of bounds and the grow option is set.

    Parameter bitIndex

    Bit index to set.

    Parameter value

    Value to set the bit to. Defaults to true.

method setAll

setAll: (array: ArrayLike<boolean>, offset?: number) => void;
  • Sets a value or an array of values.

    Parameter array

    An array of booleans to set.

    Parameter offset

    The bit offset at which the values are to be written.

Package Files (1)

Dependencies (0)

No dependencies.

Dev Dependencies (10)

Peer Dependencies (0)

No peer dependencies.

Badge

To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/bitfield.

  • Markdown
    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/bitfield)
  • HTML
    <a href="https://www.jsdocs.io/package/bitfield"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>