Chunk-based File Copy Function

  • Share this:

Code introduction


This function reads an input file and writes its content to an output file in chunks, using built-in file operations.


Technology Stack : File operations

Code Type : File operation

Code Difficulty : Intermediate


                
                    
def zip_file(input_file, output_file):
    with open(input_file, 'rb') as f_in:
        with open(output_file, 'wb') as f_out:
            while chunk := f_in.read(1024):
                f_out.write(chunk)