def cp(f1, f2, length=None, bufsize=64 * 1024):
    """Copy all data from one file to another.

    It copies the data from the current position of the input file (f1)
    appending it to the current position of the output file (f2).

    It copies at most 'length' bytes. If 'length' isn't given, it copies
    until the end of the input file.
    """
    read = f1.read
    write = f2.write
    n = bufsize
    if length is None:
        old_pos = f1.tell()
        f1.seek(0, 2)
        length = f1.tell()
        f1.seek(old_pos)
    while length > 0:
        if n > length:
            n = length
        data = read(n)
        if not data:
            break
        write(data)
        length -= len(data)
