Skip to content

Commit

Permalink
Merge pull request #5 from freefood89/master
Browse files Browse the repository at this point in the history
Change output_buffer to stream
  • Loading branch information
delimitry committed Jan 5, 2020
2 parents 25db0e1 + c5d5f8c commit 0fad32e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions compressed_rtf/compressed_rtf.py
Expand Up @@ -121,7 +121,7 @@ def decompress(data):
if len(data) < 16:
raise Exception('Data must be at least 16 bytes long')
write_offset = INIT_DICT_SIZE
output_buffer = b''
output_buffer = BytesIO()
# make stream
in_stream = BytesIO(data)

Expand Down Expand Up @@ -164,22 +164,25 @@ def decompress(data):
for step in range(actual_length):
read_offset = (offset + step) % MAX_DICT_SIZE
char = init_dict[read_offset]
output_buffer += bytes([char]) if PY3 else char
if PY3:
output_buffer.write(bytes([char]))
else:
output_buffer.write(char)
init_dict[write_offset] = char
write_offset = (write_offset + 1) % MAX_DICT_SIZE
else:
# token is literal (8 bit)
val = contents.read(1)
if not val:
break
output_buffer += val
output_buffer.write(val)
init_dict[write_offset] = ord(val) if PY3 else val
write_offset = (write_offset + 1) % MAX_DICT_SIZE
elif comp_type == UNCOMPRESSED:
return contents.read(raw_size)
else:
raise Exception('Unknown type of RTF compression!')
return output_buffer
return output_buffer.getvalue()


def _find_longest_match(init_dict, stream, write_offset):
Expand Down

0 comments on commit 0fad32e

Please sign in to comment.