brotli
Advanced tools
Comparing version 1.2.0 to 1.3.0
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; | ||
}; |
@@ -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
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1
62
1503772
20
13738
1
3
+ Addedbase64-js@^1.1.2
+ Addedbase64-js@1.5.1(transitive)
- Removedbrfs@^1.4.0
- Removedpako@^0.2.6
- Removedthrough@^2.3.6
- Removedacorn@7.4.1(transitive)
- Removedbrfs@1.6.1(transitive)
- Removedbuffer-equal@0.0.1(transitive)
- Removedbuffer-from@1.1.2(transitive)
- Removedconcat-stream@1.6.2(transitive)
- Removedconvert-source-map@1.9.0(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddeep-is@0.1.4(transitive)
- Removedduplexer2@0.1.4(transitive)
- Removedescodegen@1.9.12.1.0(transitive)
- Removedesprima@3.1.34.0.1(transitive)
- Removedestraverse@4.3.05.3.0(transitive)
- Removedesutils@2.0.3(transitive)
- Removedfalafel@2.2.5(transitive)
- Removedfast-levenshtein@2.0.6(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedhas@1.0.4(transitive)
- Removedhasown@2.0.2(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-core-module@2.13.1(transitive)
- Removedisarray@1.0.02.0.5(transitive)
- Removedlevn@0.3.0(transitive)
- Removedmagic-string@0.22.5(transitive)
- Removedmerge-source-map@1.0.4(transitive)
- Removedminimist@1.2.8(transitive)
- Removedobject-inspect@1.4.1(transitive)
- Removedoptionator@0.8.3(transitive)
- Removedpako@0.2.9(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedprelude-ls@1.1.2(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedquote-stream@1.0.2(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedresolve@1.22.8(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedshallow-copy@0.0.1(transitive)
- Removedsource-map@0.5.70.6.1(transitive)
- Removedstatic-eval@2.1.1(transitive)
- Removedstatic-module@2.2.5(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedthrough@2.3.8(transitive)
- Removedthrough2@2.0.5(transitive)
- Removedtype-check@0.3.2(transitive)
- Removedtypedarray@0.0.6(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedvlq@0.2.3(transitive)
- Removedword-wrap@1.2.5(transitive)
- Removedxtend@4.0.2(transitive)