Is there any simple way for me to read the contents of a binary file as a binary string, turn it into a normal (utf-8) string, do some operations with it, turn it back into a binary string and write it into a binary file? I tried doing something as simple as:
a_file = open('image1.png', 'rb')
text = b''
for a_line in a_file:
text += a_line
a_file.close()
text2 = text.decode('utf-8')
text3 = text2.encode()
a_file = open('image2.png', 'wb')
a_file.write(text3)
a_file.close()
but I get 'Unicode can not decode bytes in position...'
What am I doing terribly wrong?