-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a9ac63
commit 4f0cfb0
Showing
6 changed files
with
76 additions
and
9 deletions.
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,26 @@ | ||
name: Test | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.11"] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pytest mypy | ||
- name: Run tests | ||
run: | | ||
pytest tests/ | ||
# - name: Check types with mypy | ||
# run: | | ||
# mypy . |
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,2 @@ | ||
__pycache__/ | ||
*.pyc |
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,3 @@ | ||
[pytest] | ||
pythonpath = . | ||
|
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 |
---|---|---|
@@ -1,3 +1,22 @@ | ||
# huffman-py | ||
|
||
Teeworlds huffman compression ported to python. Work in progress. Not working yet. | ||
Teeworlds huffman compression ported to python. Work in progress. | ||
|
||
This is not a general purpose compression library. It uses the teeworlds frequency table | ||
and is intended to be used for teeworlds networking. | ||
|
||
## example usage | ||
|
||
```python | ||
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' | ||
``` | ||
|
||
## similar projects | ||
|
||
- teeworlds huffman (ruby) https://github.com/ChillerDragon/huffman-tw | ||
- teeworlds huffman (rust) https://github.com/edg-l/rustyman | ||
|
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
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,23 @@ | ||
from huffman import Huffman | ||
|
||
def test_huffman(): | ||
huffman = Huffman() | ||
compressed = b'\x4a\x42\x88\x4a\x6e\x16\xba\x31\x46\xa2\x84\x9e\xbf\xe2\x06' | ||
decompressed = huffman.decompress(compressed) | ||
expected = b'\x40\x02\x02\x02\x00\x40\x07\x03\x22\x01\x00\x01\x00\x01\x08\x40\x01\x04\x0b' | ||
assert decompressed == expected | ||
|
||
def test_huffman_hello_world(): | ||
huffman = Huffman() | ||
compressed = bytes([174, 149, 19, 92, 9, 87, 194, 22, 177, 86, 220, 218, 34, 56, 185, 18, 156, 168, 184, 1]) | ||
decompressed = huffman.decompress(compressed) | ||
expected = b'hello world' | ||
assert decompressed == expected | ||
|
||
def test_huffman_A(): | ||
huffman = Huffman() | ||
compressed = bytes([188, 21, 55, 0]) | ||
decompressed = huffman.decompress(compressed) | ||
expected = b'A' | ||
assert decompressed == expected | ||
|