-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
brotli: add brotli support #20458
Closed
Closed
brotli: add brotli support #20458
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a295f2a
deps: add brotli
Hackzzila 5d82880
brotli: add brotli
Hackzzila 52e2070
benchmark,test: add brotli
Hackzzila 2154080
doc, test: add brotli and fix tests
Hackzzila 54aa2e7
doc: improve brotli docs
Hackzzila 69cc504
doc: make acceptEncoding const
Hackzzila 5eb194f
doc: small brotli doc fixes
Hackzzila 72c2d4e
doc: small doc fixes
Hackzzila be82db1
brotli,doc,src,test: remove copyright headers, small doc/code fixes
Hackzzila ccc89f2
deps,tools: update license-builder.sh and LICENSE
Hackzzila fcae0ef
Merge branch 'master' into brotli-dev
Hackzzila File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Flags: --expose-brotli | ||
'use strict'; | ||
const common = require('../common.js'); | ||
const brotli = require('brotli'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
type: ['Compress', 'Decompress'], | ||
options: ['true', 'false'], | ||
n: [5e5] | ||
}); | ||
|
||
function main({ n, type, options }) { | ||
var i = 0; | ||
|
||
if (options === 'true') { | ||
const opts = {}; | ||
bench.start(); | ||
for (; i < n; ++i) | ||
new brotli[type](opts); | ||
bench.end(n); | ||
} else { | ||
bench.start(); | ||
for (; i < n; ++i) | ||
new brotli[type](); | ||
bench.end(n); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Flags: --expose-brotli | ||
'use strict'; | ||
const common = require('../common.js'); | ||
const brotli = require('brotli'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
method: ['Compress', 'compress', 'compressSync'], | ||
quality: [4, 11], | ||
inputLen: [1024], | ||
n: [4e5] | ||
}); | ||
|
||
function main({ n, method, inputLen, quality }) { | ||
const chunk = Buffer.alloc(inputLen, 'a'); | ||
|
||
var i = 0; | ||
switch (method) { | ||
// Performs `n` writes for a single deflate stream | ||
case 'Compress': | ||
const compress = new brotli.Compress({ quality }); | ||
compress.resume(); | ||
compress.on('finish', () => { | ||
bench.end(n); | ||
}); | ||
|
||
bench.start(); | ||
(function next() { | ||
if (i++ === n) | ||
return compress.end(); | ||
compress.write(chunk, next); | ||
})(); | ||
break; | ||
// Performs `n` single deflate operations | ||
case 'compress': | ||
bench.start(); | ||
(function next(err, result) { | ||
if (i++ === n) | ||
return bench.end(n); | ||
brotli.compress(chunk, { quality }, next); | ||
})(); | ||
break; | ||
// Performs `n` single deflateSync operations | ||
case 'compressSync': | ||
bench.start(); | ||
for (; i < n; ++i) | ||
brotli.compressSync(chunk, { quality }); | ||
bench.end(n); | ||
break; | ||
default: | ||
throw new Error('Unsupported method'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2009, 2010, 2013-2016 by the Brotli Authors. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
'targets': [ | ||
{ | ||
'target_name': 'brotli', | ||
'type': 'static_library', | ||
'include_dirs': ['c/include'], | ||
'conditions': [ | ||
['OS=="linux"', { | ||
'defines': [ | ||
'OS_LINUX' | ||
] | ||
}], | ||
['OS=="freebsd"', { | ||
'defines': [ | ||
'OS_FREEBSD' | ||
] | ||
}], | ||
['OS=="mac"', { | ||
'defines': [ | ||
'OS_MACOSX' | ||
] | ||
}], | ||
], | ||
'direct_dependent_settings': { | ||
'include_dirs': [ 'c/include' ] | ||
}, | ||
'libraries': [ | ||
'-lm', | ||
], | ||
'sources': [ | ||
# Common | ||
'c/common/dictionary.c', | ||
'c/common/transform.c', | ||
|
||
# Decoder | ||
'c/dec/bit_reader.c', | ||
'c/dec/decode.c', | ||
'c/dec/huffman.c', | ||
'c/dec/state.c', | ||
|
||
# Encoder | ||
'c/enc/backward_references.c', | ||
'c/enc/backward_references_hq.c', | ||
'c/enc/bit_cost.c', | ||
'c/enc/block_splitter.c', | ||
'c/enc/brotli_bit_stream.c', | ||
'c/enc/cluster.c', | ||
'c/enc/compress_fragment.c', | ||
'c/enc/compress_fragment_two_pass.c', | ||
'c/enc/dictionary_hash.c', | ||
'c/enc/encode.c', | ||
'c/enc/encoder_dict.c', | ||
'c/enc/entropy_encode.c', | ||
'c/enc/histogram.c', | ||
'c/enc/literal_cost.c', | ||
'c/enc/memory.c', | ||
'c/enc/metablock.c', | ||
'c/enc/static_dict.c', | ||
'c/enc/utf8_util.c' | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* Copyright 2016 Google Inc. All Rights Reserved. | ||
|
||
Distributed under MIT license. | ||
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
#ifndef BROTLI_COMMON_CONSTANTS_H_ | ||
#define BROTLI_COMMON_CONSTANTS_H_ | ||
|
||
/* Specification: 7.3. Encoding of the context map */ | ||
#define BROTLI_CONTEXT_MAP_MAX_RLE 16 | ||
|
||
/* Specification: 2. Compressed representation overview */ | ||
#define BROTLI_MAX_NUMBER_OF_BLOCK_TYPES 256 | ||
|
||
/* Specification: 3.3. Alphabet sizes: insert-and-copy length */ | ||
#define BROTLI_NUM_LITERAL_SYMBOLS 256 | ||
#define BROTLI_NUM_COMMAND_SYMBOLS 704 | ||
#define BROTLI_NUM_BLOCK_LEN_SYMBOLS 26 | ||
#define BROTLI_MAX_CONTEXT_MAP_SYMBOLS (BROTLI_MAX_NUMBER_OF_BLOCK_TYPES + \ | ||
BROTLI_CONTEXT_MAP_MAX_RLE) | ||
#define BROTLI_MAX_BLOCK_TYPE_SYMBOLS (BROTLI_MAX_NUMBER_OF_BLOCK_TYPES + 2) | ||
|
||
/* Specification: 3.5. Complex prefix codes */ | ||
#define BROTLI_REPEAT_PREVIOUS_CODE_LENGTH 16 | ||
#define BROTLI_REPEAT_ZERO_CODE_LENGTH 17 | ||
#define BROTLI_CODE_LENGTH_CODES (BROTLI_REPEAT_ZERO_CODE_LENGTH + 1) | ||
/* "code length of 8 is repeated" */ | ||
#define BROTLI_INITIAL_REPEATED_CODE_LENGTH 8 | ||
|
||
/* "Large Window Brotli" */ | ||
#define BROTLI_LARGE_MAX_DISTANCE_BITS 62U | ||
#define BROTLI_LARGE_MIN_WBITS 10 | ||
#define BROTLI_LARGE_MAX_WBITS 30 | ||
|
||
/* Specification: 4. Encoding of distances */ | ||
#define BROTLI_NUM_DISTANCE_SHORT_CODES 16 | ||
#define BROTLI_MAX_NPOSTFIX 3 | ||
#define BROTLI_MAX_NDIRECT 120 | ||
#define BROTLI_MAX_DISTANCE_BITS 24U | ||
#define BROTLI_DISTANCE_ALPHABET_SIZE(NPOSTFIX, NDIRECT, MAXNBITS) ( \ | ||
BROTLI_NUM_DISTANCE_SHORT_CODES + (NDIRECT) + \ | ||
((MAXNBITS) << ((NPOSTFIX) + 1))) | ||
/* BROTLI_NUM_DISTANCE_SYMBOLS == 1128 */ | ||
#define BROTLI_NUM_DISTANCE_SYMBOLS \ | ||
BROTLI_DISTANCE_ALPHABET_SIZE( \ | ||
BROTLI_MAX_NDIRECT, BROTLI_MAX_NPOSTFIX, BROTLI_LARGE_MAX_DISTANCE_BITS) | ||
#define BROTLI_MAX_DISTANCE 0x3FFFFFC | ||
#define BROTLI_MAX_ALLOWED_DISTANCE 0x7FFFFFFC | ||
|
||
/* 7.1. Context modes and context ID lookup for literals */ | ||
/* "context IDs for literals are in the range of 0..63" */ | ||
#define BROTLI_LITERAL_CONTEXT_BITS 6 | ||
|
||
/* 7.2. Context ID for distances */ | ||
#define BROTLI_DISTANCE_CONTEXT_BITS 2 | ||
|
||
/* 9.1. Format of the Stream Header */ | ||
/* Number of slack bytes for window size. Don't confuse | ||
with BROTLI_NUM_DISTANCE_SHORT_CODES. */ | ||
#define BROTLI_WINDOW_GAP 16 | ||
#define BROTLI_MAX_BACKWARD_LIMIT(W) (((size_t)1 << (W)) - BROTLI_WINDOW_GAP) | ||
|
||
#endif /* BROTLI_COMMON_CONSTANTS_H_ */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd generally much prefer a much more generic module namespace for this... e.g.
require {brotli} = require('compression')
or some such, but I can live with this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
@node/compression
(or similar) would be good, because thecompression
package is quite popular.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of the scope. we can alias other compression modules into there as well