![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
brotli-size
Advanced tools
The brotli-size npm package is used to calculate the Brotli-compressed size of a given string or buffer. Brotli is a compression algorithm developed by Google that is particularly effective for web content compression.
Calculate Brotli size of a string
This feature allows you to calculate the Brotli-compressed size of a given string synchronously. The code sample demonstrates how to import the brotli-size package, define a string, and then calculate and log its Brotli-compressed size.
const brotliSize = require('brotli-size');
const input = 'Hello, world!';
const size = brotliSize.sync(input);
console.log(`Brotli size: ${size} bytes`);
Calculate Brotli size of a buffer
This feature allows you to calculate the Brotli-compressed size of a given buffer synchronously. The code sample demonstrates how to import the brotli-size package, create a buffer from a string, and then calculate and log its Brotli-compressed size.
const brotliSize = require('brotli-size');
const input = Buffer.from('Hello, world!');
const size = brotliSize.sync(input);
console.log(`Brotli size: ${size} bytes`);
Asynchronous calculation of Brotli size
This feature allows you to calculate the Brotli-compressed size of a given string asynchronously. The code sample demonstrates how to import the brotli-size package, define a string, and then calculate and log its Brotli-compressed size using a promise.
const brotliSize = require('brotli-size');
const input = 'Hello, world!';
brotliSize(input).then(size => {
console.log(`Brotli size: ${size} bytes`);
});
The gzip-size package calculates the Gzip-compressed size of a given string or buffer. It is similar to brotli-size but uses the Gzip compression algorithm instead of Brotli. Gzip is widely supported and commonly used for web content compression.
The zlib package is a core Node.js module that provides compression and decompression functionalities using various algorithms, including Gzip and Deflate. While it is more versatile and powerful than brotli-size, it requires more setup and configuration to calculate compressed sizes.
The compress-brotli package provides Brotli compression and decompression functionalities. It is more comprehensive than brotli-size, offering more control over the compression process, but it is also more complex to use for simple size calculations.
brotli-size
Get the brotli compressed size of a string or buffer.
$ npm install --save brotli-size
var brotliSize = require('brotli-size');
var str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam feugiat, mauris non aliquam pretium, libero nulla ultrices lacus, nec varius est purus sit amet dolor.';
console.log(str.length); // 165
console.log(brotliSize.sync(str)); // 118
Type: string
, buffer
Returns a passthrough stream. The stream emits a brotli-size
event and
has a brotliSize
property.
FAQs
Get the brotli compressed size of a string or buffer
The npm package brotli-size receives a total of 196,380 weekly downloads. As such, brotli-size popularity was classified as popular.
We found that brotli-size 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.