def sizeof_fmt(num):
    """ Returns a human-friendly string when given a size in bytes """
    for x in ['bytes', 'kB', 'MB', 'GB', 'TB']:
        if num < 1024.0:
            return '%3.1f %s' % (num, x)
        num /= 1024.0
