Reputation: 396
My goal is to read a binary file and convert it to text. My code is :
def binary_to_text(self,file_name):
open_file = open(file_name,"rb")
with open("Binary2Text.txt", "a") as the_file:
for line in open_file:
the_file.write(binascii.b2a_uu(line))
I'm getting this error:
binascii.Error: At most 45 bytes at once
Is there a way to get around this, or is there another module I can use besides binascii? Thanks!
Upvotes: 1
Views: 1693
Reputation: 106445
The binascii.b2a_uu
method is meant to be a low-level function for performing uuencode, in which the algorithm encodes text input in 45-byte chunks, which is why there is a 45-byte chunk limit for input.
Unless you're trying to implement uuencode yourself, you should simply use the uu.encode
method instead:
import uu
def binary_to_text(self, file_name):
with open("Binary2Text.txt", "a") as the_file:
the_file.write(uu.encode(file_name))
Upvotes: 1