I'm working on a project with huge files that contain only the set {[0-9],.}. Encoding in UTF-8 or ASCII make huge files.
I wonder if I could find a way to encode in only 4 bits (make those file 16 times smaller). I would have enough of 16 characters!
How could I proceed? I'm working on python and I have tried the following code. Seems like the computer doesn't want it, because it only erases what was in the text file...
def encodeData(self, filePath):
print("File size before 4bits Encoding = {} Bits" .format(os.path.getsize(filePath)))
print("Proceed with '{}' 4 bit Encoding... ".format(filePath))
with open(filePath, "w+") as file2encode:
for line in file2encode.readlines():
for i in len(line):
line[i] = 0x4
print("File size After 4bits Encoding = {} Bits".format(os.path.getsize(filePath)))
Is there a way I can play with 4 bit encoding?
with open(filePath, "r") as f:
first to read from the the file, then usew+
orwb
(write as bytes) to write back, so it won't "only erases what was in the text file"