![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
fastintcompression
Advanced tools
This is an integer compression library in JavaScript, useful for work on indexes. Given an array of small integers, it produces an ArrayBuffer that uses far fewer bytes than the original (using VByte compression). It assumes a modern JavaScript engine with typed arrays.
From the compressed data, you can later recover the original array quickly (at a rate of millions of integers per second).
// var FastIntegerCompression = require("fastintcompression");// if you use node
var array = [10,100000,65999,10,10,0,1,1,2000,0xFFFFFFFF];
var buf = FastIntegerCompression.compress(array);
var back = FastIntegerCompression.uncompress(buf); // gets back [10,100000,65999,10,10,0,1,1,2000]
By default, non-negative 32-bit integers are expected. If you have signed (negative and positive) 32-bit integers, then you must use distinct functions since we need to code the sign bit:
// var FastIntegerCompression = require("fastintcompression");// if you use node
var array = [10,100000,65999,10,10,0,-1,-1,-2000];
var buf = FastIntegerCompression.compressSigned(array);
var back = FastIntegerCompression.uncompressSigned(buf); // gets back [10,100000,65999,10,10,0,-1,-1,-2000]
You can install the library under node with the command line
npm install fastintcompression
This code is made available under the Apache License 2.0.
This library is meant to compress arrays of small integers. It is not meant to compress text documents or arrays of large (or random) integers.
Go to benchmark repository (check the README.md file) and run the benchmark:
$ node test.js
Platform: linux 3.13.0-91-generic x64
Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Node version 4.5.0, v8 version 4.5.103.37
input size: 7.813K compressed size: 1000B
FastIntegerCompression.compress x 337,845 ops/sec ±0.93% (92 runs sampled)
Fastest is FastIntegerCompression.compress
FastIntegerCompression.uncompress x 187,694 ops/sec ±0.72% (93 runs sampled)
Fastest is FastIntegerCompression.uncompress
These numbers means that we can uncompress 187,694 1000-integer arrays per second. That's 187 millions of integers per second.
If you like this library, you might also like
FAQs
a fast integer compression library in JavaScript
The npm package fastintcompression receives a total of 62 weekly downloads. As such, fastintcompression popularity was classified as not popular.
We found that fastintcompression 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.