Skip to content

Commit

Permalink
update python header parser and python test to use base128 encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
danielrh committed Jan 16, 2019
1 parent 5399408 commit ca0a39f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion c/py/brotli.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ def BrotliParseHeader(raw_data):
size_le = data[byte_offset + 4:byte_offset + num_raw_header_bytes]
total_size = 0
for index in range(len(size_le)):
total_size += size_le[index] << (8 * index)
total_size += (size_le[index] & 0x7f) << (7 * index)
if not (size_le[index] & 0x80):
break
return (version, total_size)


Expand Down
13 changes: 13 additions & 0 deletions c/py/brotli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ def test_wp_rt(self):
rt = BrotliDecode(output)
assert rt == self.test_data
assert len(output) < 1024 * 1024

def test_header(self):
data = ''.join(chr(x) for x in [
0x6b, 0x1d, 0x00, 0xe1, 0x97, 0x81, 0x01, 0xe8, 0x99, 0xf4, 0x01, 0x08,
0x00, 0x08, 0x79, 0x0a, 0x2c, 0x67, 0xe8, 0x81, 0x5f, 0x22, 0x2f, 0x1e,
0x8b, 0x08, 0x3e, 0x09, 0x7a, 0x06
])
parsed_header = BrotliParseHeader(data)
assert parsed_header
version, size = parsed_header
assert size == 4001000
assert version == 1

def test_rt(self):
output = BrotliCompress(self.test_data,
{
Expand Down

0 comments on commit ca0a39f

Please sign in to comment.