Socket
Socket
Sign inDemoInstall

brotli

Package Overview
Dependencies
1
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.0 to 1.3.0

build/mem.js

43

compress.js
var brotli = require('./build/encode');
module.exports = require('./src/compress').bind(brotli);
/**
* Compresses the given buffer
* The second parameter is optional and specifies whether the buffer is
* text or binary data (the default is binary).
* Returns null on error
*/
module.exports = function(buffer, opts) {
// default to binary data
var quality = 11;
var mode = 0;
var lgwin = 22;
if (typeof opts === 'boolean') {
mode = opts ? 0 : 1;
} else if (typeof opts === 'object') {
quality = opts.quality || 11;
mode = opts.mode || 0;
mode = opts.lgwin || 22;
}
// allocate input buffer and copy data to it
var buf = brotli._malloc(buffer.length);
brotli.HEAPU8.set(buffer, buf);
// allocate output buffer (same size + some padding to be sure it fits), and encode
var outBuf = brotli._malloc(buffer.length + 1024);
var encodedSize = brotli._encode(11, 0, mode, buffer.length, buf, buffer.length, outBuf);
var outBuffer = null;
if (encodedSize !== -1) {
// allocate and copy data to an output buffer
outBuffer = new Uint8Array(encodedSize);
outBuffer.set(brotli.HEAPU8.subarray(outBuf, outBuf + encodedSize));
}
// free malloc'd buffers
brotli._free(buf);
brotli._free(outBuf);
return outBuffer;
};

17

dec/decode.js

@@ -585,7 +585,7 @@ /* Copyright 2013 Google Inc. All Rights Reserved.

if (output.pos < output_buffer.length) {
output_buffer = output_buffer.subarray(0, output.pos);
if (output.pos < output.buffer.length) {
output.buffer = output.buffer.subarray(0, output.pos);
}
return output_buffer;
return output.buffer;
}

@@ -679,2 +679,8 @@

meta_block_remaining_len = _out.meta_block_length;
if (pos + meta_block_remaining_len > output.buffer.length) {
/* We need to grow the output buffer to fit the additional data. */
var tmp = new Uint8Array( pos + meta_block_remaining_len );
tmp.set( output.buffer );
output.buffer = tmp;
}
input_end = _out.input_end;

@@ -726,3 +732,4 @@ is_uncompressed = _out.is_uncompressed;

for (i = 0; i < num_block_types[0]; ++i) {
context_modes[i] = (br.readBits(2) << 1);
br.readMoreInput();
context_modes[i] = (br.readBits(2) << 1);
}

@@ -790,2 +797,4 @@

br.readBits(Prefix.kCopyLengthPrefixCode[copy_code].nbits);
prev_byte1 = ringbuffer[pos-1 & ringbuffer_mask];
prev_byte2 = ringbuffer[pos-2 & ringbuffer_mask];
for (j = 0; j < insert_length; ++j) {

@@ -792,0 +801,0 @@ br.readMoreInput();

@@ -13,4 +13,4 @@ var base64 = require('base64-js');

var BrotliDecompressBuffer = require('./decode').BrotliDecompressBuffer;
var compressed = base64.toByteArray(fs.readFileSync(__dirname + '/dictionary.bin', 'base64'));
var compressed = base64.toByteArray(require('./dictionary.bin.js'));
return BrotliDecompressBuffer(compressed);
};
{
"name": "brotli",
"version": "1.2.0",
"version": "1.3.0",
"description": "A port of the Brotli compression algorithm as used in WOFF2",

@@ -23,5 +23,3 @@ "main": "index.js",

"dependencies": {
"brfs": "^1.4.0",
"pako": "^0.2.6",
"through": "^2.3.6"
"base64-js": "^1.1.2"
},

@@ -34,10 +32,6 @@ "devDependencies": {

},
"browserify": {
"transform": [
"./src/transform"
]
},
"scripts": {
"test": "mocha"
"test": "mocha",
"prepublish": "make"
}
}

@@ -45,5 +45,3 @@ # Brotli.js

Compresses the given buffer. Pass `true` as the second argument if the input
buffer is text data. Pass `false` or nothing if it is binary. This function
is known to be quite slow.
Compresses the given buffer. Pass optional parameters as the second argument.

@@ -54,4 +52,8 @@ ```javascript

// encode some text data
brotli.compress(fs.readFileSync('myfile.bin'), true);
// encode some data with options (default options shown)
brotli.compress(fs.readFileSync('myfile.bin'), {
mode: 0, // 0 = generic, 1 = text, 2 = font (WOFF2)
quality: 11, // 0 - 11
lgwin: 22 // window size
});
```

@@ -58,0 +60,0 @@

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc