- Fast encode datasets
- Fast decode answering
- Decode binary files to a normal view
- Prepare text/numeric data for training an ML regressor
pip install megabytehttps://github.com/vlad-technology/megabyte
from megabyte import (
anytotextbytes,
anytotextlatin,
textencoder_ascii,
textdecoder_ascii,
fileencoder_ascii,
fileencoder_ascii_latin1,
filedecoder_ascii,
)Reads a binary file and returns its raw Python bytes representation as a string.
path1 = "YOUR_BINARY_FILE_PATH"
print(anytotextbytes(path1))Reads a binary file and decodes it using latin-1, so every byte (0-255) maps to exactly one character with no data loss. Recommended for encoding arbitrary binary files (images, executables, archives, etc.).
path1 = "YOUR_BINARY_FILE_PATH"
print(anytotextlatin(path1))Encodes a string of ASCII characters (codes 0-127) into a numeric string representation.
text = "YOUR_TEXT"
print(textencoder_ascii(text))Decodes a numeric string (produced by textencoder_ascii) back into the original text.
numbers = "YOUR_NUMBERS"
print(textdecoder_ascii(numbers))Encodes any file into a .txt file containing its ASCII-numeric representation.
if fileencoder_ascii("YOUR_FILE_PATH") == True:
print("Successfully encoded")
else:
print("Bad file")Same as fileencoder_ascii, but reads the source file through latin-1 decoding first — recommended for binary files, since it preserves every byte without loss.
if fileencoder_ascii_latin1("YOUR_FILE_PATH") == True:
print("Successfully encoded")
else:
print("Bad file")Decodes a .txt file (previously produced by fileencoder_ascii / fileencoder_ascii_latin1) back into its original numeric-to-text form.
if filedecoder_ascii("YOUR_ENCODED_FILE_PATH.txt") == True:
print("Successfully decoded")
else:
print("Bad file")- Only characters with ASCII codes
0-127are encoded; bytes outside this range (128-255) are skipped. - For binary files, prefer
fileencoder_ascii_latin1overfileencoder_ascii— it avoids corrupting the byte stream during the read step. - Output files are written with
.txtappended to the original filename (e.g.image.png→image.png.txt).
MIT