Adds given file's length in front (using Elias gamma coding) of the compressed string
(source_path: str, compressed: str)
| 72 | |
| 73 | |
| 74 | def add_file_length(source_path: str, compressed: str) -> str: |
| 75 | """ |
| 76 | Adds given file's length in front (using Elias gamma coding) of the compressed |
| 77 | string |
| 78 | """ |
| 79 | file_length = os.path.getsize(source_path) |
| 80 | file_length_binary = bin(file_length)[2:] |
| 81 | length_length = len(file_length_binary) |
| 82 | |
| 83 | return "0" * (length_length - 1) + file_length_binary + compressed |
| 84 | |
| 85 | |
| 86 | def write_file_binary(file_path: str, to_write: str) -> None: |