def sizeof_fmt(num):
    """
    Formats number of bytes into a human readable form.

    From:
    """
    for size in ['bytes', 'KB', 'MB', 'GB']:
        if -1024.0 < num < 1024.0:
            return '%3.1f %s' % (num, size)
        num /= 1024.0
    return '%3.1f %s' % (num, 'TB')
