Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
This package provides you with a big map.
It uses Buffer as its storage space rather than heap memory.
It implemented by node js pure javascript code (ES6), no other dependencies.
Its feature is still relatively simple, and performance worse than build-in Object or Map,
but sometimes in order to get more space, we have no other choice.
Use Buffer implementation does not exist v8 engine heap memory limit of 1.4GB,
you can store 4GB, 8GB or more data therein, as long as sufficient physical memory.
it needs node version >= 4.0 to support some es6 features. (arrow function, let ... )
npm install big-map
var BigMap = require('big-map');
var bigmap = new BigMap(16, 16);
bigmap.set('hello', 'world');
// -> true
bigmap.get('hello')
// -> 'world'
var BigMap = require('big-map');
var bigmap = new BigMap(32, 32);
var v8 = require('v8');
console.log('before: ', v8.getHeapStatistics().used_heap_size);
for (var i = 0; i < 1024 * 128; i ++ ) {
bigmap.set('it\'s a long string key ' + i, 'it\'s a long string value' + i);
}
console.log('after: ', v8.getHeapStatistics().used_heap_size);
On my Mac, before is 10018984 and after is 10731160. the heap memory almost not change.
var obj = {};
var v8 = require('v8');
console.log('before: ', v8.getHeapStatistics().used_heap_size);
for (var i = 0; i < 1024 * 128; i ++ ) {
obj['it\'s a long string key ' + i] = 'it\'s a long string value' + i;
}
console.log('after: ', v8.getHeapStatistics().used_heap_size);
As contrast, after the codes above, heap memory increase from 9400024 to 33636280, it grows 23MB. it has 128K key/value pairs, 23MB / 128K = 184 Byte per key/value pair costs.
construct a new BigMap
key_length
: required. specify the max key string length. recommend a multiple of 4.value_length
: required. specify the max value string length. recommend a multiple of 4.options
: optional.
keyType
: only support string now.valueType
: support string and number. default is string. note: if value type set to number, the value_length will be override by 8 (DoubleFloat).loadFactor
: default is 0.75migrate
: whether rehash data from old buffer to new bigger buffer. default is falseasync_migrate
: if migrate, use async mode or sync mode. default is falseset key value pair to big map.
you should make sure the key and value has valid data type and length,
or else it will throw a error.
key
: your string keyvalue
: your value, default it needs string type. you can pass a number if you set valueType options to number.return
boolean, true if it success.
get a value by the key.
key
: your string keyreturn
string or number, depends on the options. if not find the key, return undefined.
.id
: {string} BigMap id.size
: {number} the number of the elements have been set..migrating
: {number} 0 if not in migrating status, or else, it has N MapBlocks in migrating status.FAQs
A big map, use buffer, help you exceed V8 heap memory limit
We found that big-map 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
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.