def test_base64io_encode_file(tmpdir):
source_plaintext = os.urandom(1024 * 1024)
plaintext_b64 = base64.b64encode(source_plaintext)
plaintext = tmpdir.join('plaintext')
b64_plaintext = tmpdir.join('base64_plaintext')
with open(str(plaintext), 'wb') as file:
file.write(source_plaintext)
with open(str(plaintext), 'rb') as source, open(str(b64_plaintext), 'wb') as target:
with Base64IO(target) as encoder:
for chunk in source:
encoder.write(chunk)
with open(str(b64_plaintext), 'rb') as file2:
encoded = file2.read()
assert encoded == plaintext_b64
评论列表
文章目录