You can download this code by clicking the button below.
This code is now available for download.
This function reads the binary content of two files, reading 1024 bytes at a time and returning the two byte chunks as a tuple. If the files are of unequal size, it stops at the smaller file.
Technology Stack : Built-in library: open
Code Type : File processing
Code Difficulty : Intermediate
def zipfiles(file1, file2):
with open(file1, 'rb') as f1, open(file2, 'rb') as f2:
while True:
chunk1 = f1.read(1024)
chunk2 = f2.read(1024)
if not chunk1 and not chunk2:
break
yield from (chunk1, chunk2)