bitfield

  • Version 4.0.0
  • Published
  • 12.1 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 {}

    constructor

    constructor(data?: number | Uint8Array, opts?: BitFieldOptions);
    • Parameter data

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

      Parameter opts

      Options for the bitfield.

    property buffer

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

    method forEach

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

      Parameter fn

      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: (i: number) => boolean;
    • Get a particular bit.

      Parameter i

      Bit index to retrieve.

      Returns

      A boolean indicating whether the ith bit is set.

    method set

    set: (i: 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 i

      Bit index to set.

      Parameter value

      Value to set the bit to. Defaults to true.

    Package Files (1)

    Dependencies (0)

    No dependencies.

    Dev Dependencies (12)

    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>