def humanize_bytes(n):
    """
    To convert bytes to human-readable units
    Adapted from http://stackoverflow.com/a/1094933/1979001
    """
    for unit in ['', 'KB', 'MB', 'GB', 'TB', 'PB']:
        if n < 1024.0:
            return '{:3.2f} {}'.format(n, unit)
        n /= 1024.0