Pretty print the size of the number of bytes.
513509
function bytesToSize (bytes) {
  const sizes = ['bytes', 'kb', 'mb', 'gb', 'tb']
  if (bytes === 0) return '0 byte'
  const i = parseInt(Math.floor(Math.log(bytes) / Math.log(BYTES)))
  return (bytes / Math.pow(BYTES, i)).toFixed(DISPLAY_DECIMALS) + sizes[i]
}
913210
def get_size_in_bytes(self, handle):
        """"""
        fpath = self._fpath_from_handle(handle)
        return os.stat(fpath).st_size
303579
def print_bin_sizes():
    
    for i, offset in enumerate(OFFSETS):
        binstart = offset
        try:
            binstop = OFFSETS[i + 1]
        except IndexError:
            binstop = binstart

        bin_size = 2 ** (FIRST_SHIFT + (i * NEXT_SHIFT))
        actual_size = bin_size

        # nice formatting
        bin_size, suffix = bin_size / 1024, 'Kb'
        if bin_size >= 1024:
            bin_size, suffix = bin_size / 1024, 'Mb'
        if bin_size >= 1024:
            bin_size, suffix = bin_size / 1024, 'Gb'
        size = '(%s %s)' % (bin_size, suffix)
        actual_size = '%s bp' % (actual_size)

        print('level: {i:1};  bins {binstart:<4} to {binstop:<4}; '
              'size: {actual_size:<12} {size:<6}'.format(**locals()))
309247
def _send_size(self):
        "  "
        rows, cols = _get_size(sys.stdout.fileno())
        self._send_packet({
            'cmd': 'size',
            'data': [rows, cols]
        })
8201
def _pfp__width(self):
        
        raw_output = six.BytesIO()
        output = bitwrap.BitwrappedStream(raw_output)
        self._pfp__build(output)
        output.flush()
        return len(raw_output.getvalue())
905507
def print_long(filename, stat, print_func):
    """"""
    size = stat_size(stat)
    mtime = stat_mtime(stat)
    file_mtime = time.localtime(mtime)
    curr_time = time.time()
    if mtime > (curr_time + SIX_MONTHS) or mtime < (curr_time - SIX_MONTHS):
        print_func('%6d %s %2d %04d  %s' % (size, MONTH[file_mtime[1]],
                                            file_mtime[2], file_mtime[0],
                                            decorated_filename(filename, stat)))
    else:
        print_func('%6d %s %2d %02d:%02d %s' % (size, MONTH[file_mtime[1]],
                                                file_mtime[2], file_mtime[3], file_mtime[4],
                                                decorated_filename(filename, stat)))
328626
def _chunk_length(self, data):
        """"""

        assert data[-2:] == "\r\n", "CRLF"

        length = data[:-2].split(';')[0] # cut off optional length paramters
        length = int(length.strip(), 16) # length is in hex

        if length:
            logger.debug('Got chunk length: %d', length)
            self.httpstream.read_bytes(length + 2, self._chunk_data)
        else:
            logger.debug('Got last chunk (size 0)')
            self.got_request = True
            # enable input write event so the handler can finish things up 
            # when it has written all pending data
            self.ioloop.update_handler(self.fd_stdin, self.ioloop.WRITE | self.ioloop.ERROR)
917887
def prettyprint(datastr):
    
    maxwidth = WPToolsQuery.MAXWIDTH
    rpad = WPToolsQuery.RPAD

    extent = maxwidth - (rpad + 2)
    for line in datastr:
        if len(line) >= maxwidth:
            line = line[:extent] + '...'
        utils.stderr(line)
1005952
def pretty_memory_info():
    '''
    
    '''
    process = psutil.Process(os.getpid())
    return '{}MB memory usage'.format(int(process.memory_info().rss / 2**20))
691529
def get_size_str(size):
    
    if size == 0:
        magnitude = 0
        level = 0
    else:
        magnitude = math.floor(math.log(size, 10))
        level = int(min(math.floor(magnitude // 3), 4))
    return ('%d' if level == 0 else '%.2f') % (float(size) / 2**(level*10)) + ' ' + SIZE_LEVEL[level]
604298
def _readable_part_size(num_bytes):
    ""
    B = num_bytes
    KB = float(1024)
    MB = float(KB * 1024)
    GB = float(MB * 1024)
    TB = float(GB * 1024)

    if B < KB:
        return '{0} {1}'.format(B, 'bytes' if B != 1 else 'byte')
    elif KB <= B < MB:
        return '{0:.2f} KiB'.format(B/KB)
    elif MB <= B < GB:
        return '{0:.2f} MiB'.format(B/MB)
    elif GB <= B < TB:
        return '{0:.2f} GiB'.format(B/GB)
    elif TB <= B:
        return '{0:.2f} TiB'.format(B/TB)
494910
def format_size(size):
    
    units = ['B', 'KB', 'MB', 'GB']
    unit = ''
    n = size
    old_n = n
    value = size
    for i in units:
        old_n = n
        x, y = divmod(n, 1024)
        if x == 0:
            unit = i
            value = y
            break

        n = x
        unit = i
        value = old_n
    return str(value)+unit
1178665
def calculate_size(name, count):
    
    data_size = 0
    data_size += calculate_size_str(name)
    data_size += INT_SIZE_IN_BYTES
    return data_size
1033371
def output_sizes(self):
    """"""
    return tuple([l() if callable(l) else l for l in self._output_sizes])
754170
def format_size(self, bytes):
        
        # b
        if bytes < 1024:
            return "{}{}".format(colorize(round(
                bytes, 2), "purple"),
                bold("bytes"))
        # kb
        elif bytes < (1024*1000):
            return "{}{}".format(colorize(round(
                bytes/1024, 2), "purple"),
                bold("kB"))
        # mb
        elif bytes < (1024*1024):
            return "{}{}".format(colorize(round(
                bytes/1024, 2), "purple"),
                bold("MB"))
1081573
def get_size(self):
        """"""
        self.curses.setupterm()
        return self.curses.tigetnum('cols'), self.curses.tigetnum('lines')
973239
def size(self) -> Optional[int]:
        """"""
        if not self._parts:
            return 0

        total = 0
        for part, encoding, te_encoding in self._parts:
            if encoding or te_encoding or part.size is None:
                return None

            total += int(
                2 + len(self._boundary) + 2 +  # b'--'+self._boundary+b'\r\n'
                part.size + len(part._binary_headers) +
                2  # b'\r\n'
            )

        total += 2 + len(self._boundary) + 4  # b'--'+self._boundary+b'--\r\n'
        return total