diff options
author | Eugene Kliuchnikov <eustas@google.com> | 2016-02-23 17:42:55 +0100 |
---|---|---|
committer | Eugene Kliuchnikov <eustas@google.com> | 2016-02-23 17:42:55 +0100 |
commit | 30612e3a64689dfc4aa8b79b563f6bca202135a8 (patch) | |
tree | 4ffd5cbdae86d4b28c885016adac621dd203bc10 /python/bro.py | |
parent | 5cdfb5cf507389a185cd9ddb5471a75ff093bcf7 (diff) | |
download | brotli-30612e3a64689dfc4aa8b79b563f6bca202135a8.zip brotli-30612e3a64689dfc4aa8b79b563f6bca202135a8.tar.gz brotli-30612e3a64689dfc4aa8b79b563f6bca202135a8.tar.bz2 |
Add binding for custom_dictionary.
Diffstat (limited to 'python/bro.py')
-rwxr-xr-x | python/bro.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/python/bro.py b/python/bro.py index c4cf7e2..c6f74ce 100755 --- a/python/bro.py +++ b/python/bro.py @@ -79,6 +79,8 @@ def main(args=None): help='Base 2 logarithm of the maximum input block size. ' 'Range is 16 to 24. If set to 0, the value will be set based ' 'on the quality. Defaults to 0.') + params.add_argument('--custom-dictionary', metavar="FILE", type=str, dest='dictfile', + help='Custom dictionary file.', default = None) # set default values using global DEFAULT_PARAMS dictionary parser.set_defaults(**DEFAULT_PARAMS) @@ -103,13 +105,22 @@ def main(args=None): else: outfile = get_binary_stdio('stdout') + if options.dictfile: + if not os.path.isfile(options.dictfile): + parser.error('file "%s" not found' % options.dictfile) + with open(options.dictfile, "rb") as dictfile: + custom_dictionary = dictfile.read() + else: + custom_dictionary = '' + + try: if options.decompress: - data = brotli.decompress(data) + data = brotli.decompress(data, dictionary=custom_dictionary) else: data = brotli.compress( data, mode=options.mode, quality=options.quality, - lgwin=options.lgwin, lgblock=options.lgblock) + lgwin=options.lgwin, lgblock=options.lgblock, dictionary=custom_dictionary) except brotli.error as e: parser.exit(1,'bro: error: %s: %s' % (e, options.infile or 'sys.stdin')) |