def size_as_mb(n_bytes):
    """Convert a size in bytes to a human-readable form as follows:

    If < kb return the number unchanged
    If >= kb and < mb return number of kb
    If >= mb and < gb return number of mb
    Otherwise return number of gb
    """
    n_kb, n_b = divmod(n_bytes, 1024)
    n_mb, n_kb = divmod(n_kb, 1024)
    n_gb, n_mb = divmod(n_mb, 1024)
    if n_gb > 0:
        return "%3.2fGb" % (n_bytes / 1024.0 / 1024.0 / 1024.0)
    elif n_mb > 0:
        return "%3.2fMb" % (n_bytes / 1024.0 / 1024.0)
    elif n_kb > 0:
        return "%3.2fkb" % (n_bytes / 1024.0)
    else:
        return "%d" % n_bytes