title: How to base64 encode/decode binary files in python?
body: <p>I'm trying to encode and decode the same image file using python using following simple code. But every time output file is larger than input file and it can't open. What's the problem in this code?</p>
  
  <pre><code>import base64
  
  with open("img.jpeg", "rb") as image_file:
      encoded_string = base64.b64encode(image_file.read())
  
      decoded_string = base64.b64decode(encoded_string)
      with open("test_img.jpeg", "w") as image_file2:
          image_file2.write(decoded_string);
  </code></pre>
  
  <p>Original file: <a href="https://filebin.ca/3j6aIDlWEYdV/img.jpeg" rel="noreferrer">https://filebin.ca/3j6aIDlWEYdV/img.jpeg</a> <br/>
  Result file:  <a href="https://filebin.ca/3j6arBo85Lcg/test_img.jpeg" rel="noreferrer">https://filebin.ca/3j6arBo85Lcg/test_img.jpeg</a></p>