Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
sparse-bitfield
Advanced tools
Bitfield that allocates a series of small buffers to support sparse bits without allocating a massive buffer
The sparse-bitfield package is a utility for efficiently storing and manipulating sparse bitfields. It is particularly useful for scenarios where you need to handle large arrays of boolean values or bits, but expect many of these values to be false or unset, thus allowing for memory-efficient storage and operations.
Allocation and setting bits
This feature allows for the allocation of a new bitfield and setting specific bits to true or false. It is useful for initializing and modifying bitfields.
const Bitfield = require('sparse-bitfield');
const bitfield = new Bitfield();
bitfield.set(100, true); // Sets the bit at position 100 to true
Getting bit values
This feature enables retrieving the value of a specific bit in the bitfield. It's useful for checking the state of bits.
const value = bitfield.get(100); // Retrieves the value at position 100, returns true if set, false otherwise
Memory efficiency
This feature provides information on the memory usage of the bitfield, highlighting the package's efficiency in handling sparse data.
const memoryUsage = bitfield.memoryUsage(); // Returns the amount of memory used by the bitfield
The bit-array package offers functionality for manipulating arrays of bits similar to sparse-bitfield. However, it may not be as optimized for sparse data, potentially leading to higher memory usage for sparse arrays.
bitset.js is another package for handling bit arrays, offering a wide range of operations including logical operations on bits. It differs from sparse-bitfield by providing a more comprehensive set of features for bit manipulation but may not be as focused on memory efficiency for sparse data.
Bitfield implementation that allocates a series of 1kb buffers to support sparse bitfields without allocating a massive buffer. If you want to simple implementation of a flat bitfield see the bitfield module.
This module is mostly useful if you need a big bitfield where you won't nessecarily set every bit.
npm install sparse-bitfield
var bitfield = require('sparse-bitfield')
var bits = bitfield()
bits.set(0, true) // set first bit
bits.set(1, true) // set second bit
bits.set(1000000000000, true) // set the 1.000.000.000.000th bit
Running the above example will allocate two 1kb buffers internally. Each 1kb buffer can hold information about 8192 bits so the first one will be used to store information about the first two bits and the second will be used to store the 1.000.000.000.000th bit.
var bits = bitfield([options])
Create a new bitfield. Options include
{
pageSize: 1024, // how big should the partial buffers be
buffer: anExistingBitfield,
trackUpdates: false // track when pages are being updated in the pager
}
bits.set(index, value)
Set a bit to true or false.
bits.get(index)
Get the value of a bit.
bits.pages
A memory-pager instance that is managing the underlying memory.
If you set trackUpdates
to true in the constructor you can use .lastUpdate()
on this instance to get the last updated memory page.
var buffer = bits.toBuffer()
Get a single buffer representing the entire bitfield.
MIT
FAQs
Bitfield that allocates a series of small buffers to support sparse bits without allocating a massive buffer
The npm package sparse-bitfield receives a total of 3,626,581 weekly downloads. As such, sparse-bitfield popularity was classified as popular.
We found that sparse-bitfield demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.