Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
wasm-brotli
Advanced tools
WebAssembly compiled Brotli library.
npm install -S wasm-brotli
The awesome thing about
wasm-brotli
is that it does not need to compile or download any prebuilt binaries!
Because WebAssembly is supported on both Node.js and several browsers,
wasm-brotli
is super easy to use.
An example of compressing something and saving it to a file via Node.js.
import { compress } from 'wasm-brotli';
import { writeFile } from 'fs';
import { promisify } from 'util';
const writeFileAsync = promisify(writeFile);
const content = Buffer.from('Hello, world!', 'utf8');
(async () => {
try {
const compressedContent = await compress(content);
await writeFileAsync('./hello_world.txt.br', compressedContent);
} catch (err) {
console.error(err);
}
})();
An example of compressing something and downloading it from the browser.
import { compress } from 'wasm-brotli';
const content = new TextEncoder('utf-8').encode('Hello, world!');
(async () => {
try {
const compressedContent = await compress(content);
const file = new File([compressedContent], 'hello_world.txt.br', { type: 'application/brotli' });
const link = document.createElement('a');
link.setAttribute('href', URL.createObjectURL(file));
link.setAttribute('download', file.name);
link.click();
} catch (err) {
console.error(err);
}
})();
buffer
<Uint8Array>
Compress buffer
using Brotli compression.
buffer
<Uint8Array>
Decompress buffer
using Brotli decompression.
To build wasm-brotli
you will need to install wasm-pack
. After that all
that is needed is to do the following:
Install all dependencies.
npm install
Build the module.
npm run build
Test the module.
npm test
Build wasm-brotli
if you haven't already done so—
see instructions here.
Build and run the benchmark.
npm run benchmark
Wait a while... The tests might run quite slow.
These results are run on a Dell XPS 13 9360 with an Intel® Core™ i7-7500U CPU @ 2.70GHz × 4 and 16 GB 1866 MHz DDR3 memory, running Ubuntu 19.10:
iltorb (native compress) 1 byte(s) x 5,159 ops/sec ±9.73% (66 runs sampled)
wasm-brotli (wasm compress) 1 byte(s) x 49.80 ops/sec ±0.61% (78 runs sampled)
iltorb (native compress) 1024 byte(s) x 329 ops/sec ±1.63% (81 runs sampled)
wasm-brotli (wasm compress) 1024 byte(s) x 32.33 ops/sec ±0.77% (76 runs sampled)
iltorb (native compress) 1038336 byte(s) x 2.23 ops/sec ±1.20% (15 runs sampled)
wasm-brotli (wasm compress) 1038336 byte(s) x 1.03 ops/sec ±0.93% (10 runs sampled)
FAQs
🗜 WebAssembly compiled Brotli library
The npm package wasm-brotli receives a total of 1,611 weekly downloads. As such, wasm-brotli popularity was classified as popular.
We found that wasm-brotli 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.