input = Binary file object of input file
output = Binary file object of output file
This method reads the binary input file, encode it and writes back the encoded data to the output file. Input file is read until MAXBINSIZE where it is calculated as follows.
MAXLINESIZE = 76 # Excluding the CRLF
MAXBINSIZE = (MAXLINESIZE//4)*3
Also encode() method appends a newline character (b'\n') after every 76 bytes and a trailing newline. The binascii.b2a_base64() method is used to convert binary data to a line of ASCII characters in base64 encoding in the encode method functionality.
- Input and output should be file objects
- Input and output file objects should be opened in binary mode
>>> import base64
>>> a = open("input.txt","rb")
>>> b = open("output.txt","wb")
This is a test input string.
If binary mode isn't used while opening input file the following error will occur
TypeError: a bytes-like object is required, not 'str'
If binary mode isn't used while opening output file the following error will occur
TypeError: write() argument must be str, not bytes
If no input is provided as an argument the following error will occur
TypeError: encode() missing 2 required positional arguments: 'input' and 'output'