>>> ascii85_encode(b"") b'' >>> ascii85_encode(b"12345") b'0etOA2#' >>> ascii85_encode(b"base 85") b'@UX=h+?24'
(data: bytes)
| 14 | |
| 15 | |
| 16 | def ascii85_encode(data: bytes) -> bytes: |
| 17 | """ |
| 18 | >>> ascii85_encode(b"") |
| 19 | b'' |
| 20 | >>> ascii85_encode(b"12345") |
| 21 | b'0etOA2#' |
| 22 | >>> ascii85_encode(b"base 85") |
| 23 | b'@UX=h+?24' |
| 24 | """ |
| 25 | binary_data = "".join(bin(ord(d))[2:].zfill(8) for d in data.decode("utf-8")) |
| 26 | null_values = (32 * ((len(binary_data) // 32) + 1) - len(binary_data)) // 8 |
| 27 | binary_data = binary_data.ljust(32 * ((len(binary_data) // 32) + 1), "0") |
| 28 | b85_chunks = [int(_s, 2) for _s in map("".join, zip(*[iter(binary_data)] * 32))] |
| 29 | result = "".join(_base10_to_85(chunk)[::-1] for chunk in b85_chunks) |
| 30 | return bytes(result[:-null_values] if null_values % 4 != 0 else result, "utf-8") |
| 31 | |
| 32 | |
| 33 | def ascii85_decode(data: bytes) -> bytes: |
nothing calls this directly
no test coverage detected