def format_bytes(n):
    """ Format bytes as text

    Copied from dask to avoid dependency.

    """
    if n > 1000000000000000.0:
        return '%0.2f PB' % (n / 1000000000000000.0)
    if n > 1000000000000.0:
        return '%0.2f TB' % (n / 1000000000000.0)
    if n > 1000000000.0:
        return '%0.2f GB' % (n / 1000000000.0)
    if n > 1000000.0:
        return '%0.2f MB' % (n / 1000000.0)
    if n > 1000.0:
        return '%0.2f kB' % (n / 1000)
    return '%d B' % n
