Skip to content

Commit

Permalink
Ready for usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillerDragon committed Apr 23, 2024
1 parent 7cad00e commit a9c272a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# huffman-py

Teeworlds huffman compression ported to python. Work in progress.
Teeworlds huffman compression ported to python.

This is not a general purpose compression library. It uses the teeworlds frequency table
and is intended to be used for teeworlds networking.
Expand All @@ -11,8 +11,17 @@ and is intended to be used for teeworlds networking.
from huffman import Huffman

huffman = Huffman()
decompressed = huffman.decompress(bytes([174, 149, 19, 92, 9, 87, 194, 22, 177, 86, 220, 218, 34, 56, 185, 18, 156, 168, 184, 1]))
print(decompressed) # => b'hello world'
decompressed = huffman.decompress(bytes([
174, 149, 19, 92, 9, 87, 194,
22, 177, 86, 220, 218, 34, 56,
185, 18, 156, 168, 184, 1
]))
print(decompressed)
# => b'hello world'

compressed = huffman.compress(b'hello world')
print(compressed)
# => b'\xae\x95\x13\\\tW\xc2\x16\xb1V\xdc\xda"8\xb9\x12\x9c\xa8\xb8\x01'
```

## similar projects
Expand Down
2 changes: 1 addition & 1 deletion huffman.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def compress(self, data: bytes) -> bytes:
bits >>= 8
bitcount -= 8
dst.append(bits)
return dst
return bytes(dst)

def decompress(self, data: bytes) -> bytes:
"""
Expand Down

0 comments on commit a9c272a

Please sign in to comment.