def fmt_bytes(nbytes):
    """ Returns a human readable string, given the number of bytes """
    for x in ['B', 'KB', 'MB', 'GB']:
        if nbytes < 1024.0:
            return "%3.1f%s" % (nbytes, x)
        nbytes /= 1024.0

    return "%.1f%s" % (nbytes, 'TB')