Encode method is a part of python's Lib/base64.py module. This module provides functionality for encoding binary data to printable ASCII characters and decoding such encodings back to binary, read more about the module here. There are two interfaces provided by this module. Encode method is a part of legacy interface. The legacy interface does not allow decoding from strings, but do support functions for encoding and decoding to and from file objects.
encode
(input,output)input = Binary file object of input file
output = Binary file object of output file
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.
>>> import base64
>>> a = open("input.txt","rb")
>>> b = open("output.txt","wb")
>>> base64.encode(a,b)
>>> a.close()
>>> b.close()
This is a test input string.
VGhpcyBpcyBhIHRlc3QgaW5wdXQgc3RyaW5nLgo=
TypeError: a bytes-like object is required, not 'str'
TypeError: write() argument must be str, not bytes
TypeError: encode() missing 2 required positional arguments: 'input' and 'output'
Name | Views | Likes |
---|---|---|
Python tokenize detect_encoding | 666 | 3 |
Python base64 b64decode | 1928 | 4 |
Python base64 Introduction | 837 | 4 |
Python base64 b32encode | 719 | 4 |
Python tokenize open | 632 | 3 |
Python base64 urlsafe_b64encode | 943 | 5 |
Python base64 a85encode | 811 | 3 |
Python base64 decodebytes | 829 | 4 |
Python base64 decode | 854 | 4 |
Python base64 a85decode | 1006 | 4 |
Python base64 standard_b64encode | 865 | 4 |
Python tokenize TokenError | 658 | 3 |
Python base64 b32decode | 1543 | 3 |
Python base64 b16encode | 707 | 3 |
Python tokenize using CLI | 672 | 3 |
Python base64 standard_b64decode | 634 | 4 |
Python base64 b16decode | 879 | 4 |
Python base64 encode | 833 | 4 |
Python tokenize tokenize | 677 | 3 |
Python base64 urlsafe_b64decode | 903 | 4 |
Python base64 b85encode | 751 | 3 |
Python tokenize untokenize | 734 | 3 |
Python base64 b64encode | 863 | 4 |
Python tokenize Introduction | 661 | 4 |
Python base64 b85decode | 774 | 3 |
Python tokenize generate_tokens | 665 | 3 |
Python base64 encodebytes | 794 | 3 |
Comments