def download_file(url, output_file, chunk_size=1024):
    """
    Download a file and write to disk in chunks (not in memory).

    Parameters
    ----------
    url : :obj:`str`
        URL to download from.
    output_file : :obj:`str`
        Path to file as output.
    chunk_size : :obj:`int`
        Size in bytes of chunk to write to disk at a time.
    """
    if url.startswith('ftp://'):
        import shutil
        import urllib.request as request
        from contextlib import closing
        with closing(request.urlopen(url)) as r:
            with open(output_file, 'wb') as f:
                shutil.copyfileobj(r, f)
    else:
        import requests
        response = requests.get(url, stream=True)
        with open(output_file, 'wb') as outfile:
            outfile.writelines(response.iter_content(chunk_size=chunk_size))
