Copy a file from one filesystem to another.

    If the destination exists, and is a file, it will be first truncated.

    Arguments:
        src_fs (FS or str): Source filesystem (instance or URL).
        src_path (str): Path to a file on the source filesystem.
        dst_fs (FS or str): Destination filesystem (instance or URL).
        dst_path (str): Path to a file on the destination filesystem.

def copy_file(
    src_fs,  # type: Union[FS, Text]
    src_path,  # type: Text
    dst_fs,  # type: Union[FS, Text]
    dst_path,  # type: Text
):
    # type: (...) -> None
    """Copy a file from one filesystem to another.

    If the destination exists, and is a file, it will be first truncated.

    Arguments:
        src_fs (FS or str): Source filesystem (instance or URL).
        src_path (str): Path to a file on the source filesystem.
        dst_fs (FS or str): Destination filesystem (instance or URL).
        dst_path (str): Path to a file on the destination filesystem.

    """
    with manage_fs(src_fs, writeable=False) as _src_fs:
        with manage_fs(dst_fs, create=True) as _dst_fs:
            if _src_fs is _dst_fs:
                # Same filesystem, so we can do a potentially optimized
                # copy
                _src_fs.copy(src_path, dst_path, overwrite=True)
            else:
                # Standard copy
                with _src_fs.lock(), _dst_fs.lock():
                    if _dst_fs.hassyspath(dst_path):
                        with _dst_fs.openbin(dst_path, "w") as write_file:
                            _src_fs.download(src_path, write_file)
                    else:
                        with _src_fs.openbin(src_path) as read_file:
                            _dst_fs.upload(dst_path, read_file)