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

bitfield

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitfield

a very simple bitfield implementation using buffers

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.9K
decreased by-33.84%
Maintainers
1
Weekly downloads
 
Created
Source

#bitfield

a very simple bitfield, compliant with the Bittorrent spec

npm install bitfield

####Example

var Bitfield = require("bitfield");

var field = new Bitfield(256); //create a bitfield with 256 bits

field.set(128); //set the 128th bit
field.set(128, true); //same as above

field.get(128); //true
field.get(200); //false (all values are initialised to `false`)
field.get(1e3); //false (out-of-bounds is also false)

field.set(128, false); //set the 128th bit to 0 again

field.buffer; //the buffer used by bitfield

####Methods Bitfield(data): Data can be either a node.js buffer, WebGL Int8Array or numeric array, or a number representing the maximum number of supported bytes.

Bitfield#get(index): Returns a boolean indicating whether the bit is set.

Bitfield#set(index[, value]): Values defaults to true. Sets the bit to the boolean value of the value (true = 1, false = 0).

Auto-grow mode

Bitfield(data, { grow: size }): If you set an index that is out-of-bounds, the Bitfield will automatically grow so that the bitfield is big enough to contain the given index, up to the given size. If you want the Bitfield to grow indefinitely, pass Infinity as the size.

####Properties Bitfield#buffer: The contents of the bitfield.

##License

MIT

Keywords

FAQs

Package last updated on 10 Apr 2014

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