Resize a file by `diff`.

    New space will be filled with zeros.

    Args:
        fobj (fileobj)
        diff (int): amount of size to change
    Raises:
        IOError
556230
def resize_file(fobj, diff, BUFFER_SIZE=2 ** 16):
    

    fobj.seek(0, 2)
    filesize = fobj.tell()

    if diff < 0:
        if filesize + diff < 0:
            raise ValueError
        # truncate flushes internally
        fobj.truncate(filesize + diff)
    elif diff > 0:
        try:
            while diff:
                addsize = min(BUFFER_SIZE, diff)
                fobj.write(b"\x00" * addsize)
                diff -= addsize
            fobj.flush()
        except IOError as e:
            if e.errno == errno.ENOSPC:
                # To reduce the chance of corrupt files in case of missing
                # space try to revert the file expansion back. Of course
                # in reality every in-file-write can also fail due to COW etc.
                # Note: IOError gets also raised in flush() due to buffering
                fobj.truncate(filesize)
            raise
389907
def _fileobj_to_fd(fileobj):
    
    if isinstance(fileobj, int):
        fd = fileobj
    else:
        try:
            fd = int(fileobj.fileno())
        except (AttributeError, TypeError, ValueError):
            raise ValueError("Invalid file object: {0!r}".format(fileobj))
    if fd < 0:
        raise ValueError("Invalid file descriptor: {0}".format(fd))
    return fd
1060234
def diffstat(self):
    
    names = []
    insert = []
    delete = []
    delta = 0    # size change in bytes
    namelen = 0
    maxdiff = 0  # max number of changes for single file
                 # (for histogram width calculation)
    for patch in self.items:
      i,d = 0,0
      for hunk in patch.hunks:
        for line in hunk.text:
          if line.startswith(b'+'):
            i += 1
            delta += len(line)-1
          elif line.startswith(b'-'):
            d += 1
            delta -= len(line)-1
      names.append(patch.target)
      insert.append(i)
      delete.append(d)
      namelen = max(namelen, len(patch.target))
      maxdiff = max(maxdiff, i+d)
    output = ''
    statlen = len(str(maxdiff))  # stats column width
    for i,n in enumerate(names):
      # %-19s | %-4d %s
      format = " %-" + str(namelen) + "s | %" + str(statlen) + "s %s\n"

      hist = ''
      # -- calculating histogram --
      width = len(format % ('', '', ''))
      histwidth = max(2, 80 - width)
      if maxdiff < histwidth:
        hist = "+"*insert[i] + "-"*delete[i]
      else:
        iratio = (float(insert[i]) / maxdiff) * histwidth
        dratio = (float(delete[i]) / maxdiff) * histwidth

        # make sure every entry gets at least one + or -
        iwidth = 1 if 0 < iratio < 1 else int(iratio)
        dwidth = 1 if 0 < dratio < 1 else int(dratio)
        #print(iratio, dratio, iwidth, dwidth, histwidth)
        hist = "+"*int(iwidth) + "-"*int(dwidth)
      # -- /calculating +- histogram --
      output += (format % (tostr(names[i]), str(insert[i] + delete[i]), hist))

    output += (" %d files changed, %d insertions(+), %d deletions(-), %+d bytes"
               % (len(names), sum(insert), sum(delete), delta))
    return output
266499
def resize(self, signum, obj):
        
        self.s.clear()
        stream_cursor = self.pads['streams'].getyx()[0]
        for pad in self.pads.values():
            pad.clear()
        self.s.refresh()
        self.set_screen_size()
        self.set_title(TITLE_STRING)
        self.init_help()
        self.init_streams_pad()
        self.move(stream_cursor, absolute=True, pad_name='streams', refresh=False)
        self.s.refresh()
        self.show()
911273
def compute_diff_handle(filename, old_line, code):
        
        key = "{filename}:{old_line}:{code}".format(
            filename=filename, old_line=old_line, code=code
        )
        return BaseParser.compute_handle_from_key(key)
959178
def update(self, obj, size):
        '''
        '''
        self.number += 1
        self.total  += size
        if self.high < size:  # largest
           self.high = size
           try:  # prefer using weak ref
               self.objref, self.weak = Weakref.ref(obj), True
           except TypeError:
               self.objref, self.weak = obj, False
997993
def resize(self, size):
        
        count = max(int(size), 0) - len(self)

        if count == 0:
            pass
        elif -count == len(self):
            self._value = bytes()
        elif count > 0:
            self._value += b'\x00' * count
        else:
            self._value = self._value[:count]
        size = len(self)
        self._bit_size = size * 8
        self._align_to_byte_size = size
65789
def resize(self, size=None):
        

        if not self.israw():
            return

        size = size or tty.size(self.stdout)

        if size is not None:
            rows, cols = size
            try:
                self.client.resize(self.container, height=rows, width=cols)
            except IOError: # Container already exited
                pass
1005525
def diff(cls, a, b, ignore_formatting=False):
        """"""
        def underline(x): return u'\x1b[4m%s\x1b[0m' % (x,)
        def blink(x): return u'\x1b[5m%s\x1b[0m' % (x,)
        a_rows = []
        b_rows = []
        max_width = max([len(row) for row in a] + [len(row) for row in b])
        a_lengths = []
        b_lengths = []
        for a_row, b_row in zip(a, b):
            a_lengths.append(len(a_row))
            b_lengths.append(len(b_row))
            extra_a = u'`' * (max_width - len(a_row))
            extra_b = u'`' * (max_width - len(b_row))
            a_line = u''
            b_line = u''
            for a_char, b_char in zip(a_row + extra_a, b_row + extra_b):
                if ignore_formatting:
                    a_char_for_eval = a_char.s if isinstance(a_char, FmtStr) else a_char
                    b_char_for_eval = b_char.s if isinstance(b_char, FmtStr) else b_char
                else:
                    a_char_for_eval = a_char
                    b_char_for_eval = b_char
                if a_char_for_eval == b_char_for_eval:
                    a_line += actualize(a_char)
                    b_line += actualize(b_char)
                else:
                    a_line += underline(blink(actualize(a_char)))
                    b_line += underline(blink(actualize(b_char)))
            a_rows.append(a_line)
            b_rows.append(b_line)
        hdiff = '\n'.join(a_line + u' %3d | %3d ' % (a_len, b_len) + b_line for a_line, b_line, a_len, b_len in zip(a_rows, b_rows, a_lengths, b_lengths))
        return hdiff
174197
def diff(a, b):
        
        delta = diff(a, b)
        if not a:
            return delta
        for item in delta:
            if isinstance(a[item], list):
                if delta[item] == []:
                    delta[item] = {JSONUtils.DIFF_DELETE : a[item]}
                elif isinstance(delta[item], dict):
                    for key in delta[item].keys():
                        if str(key) == JSONUtils.DIFF_DELETE:
                            delta_upd = {JSONUtils.DIFF_DELETE : []}
                            for i in delta[item][key]:
                                delta_upd[JSONUtils.DIFF_DELETE].append(a[item][i])
                                delta[item] = delta_upd
        return delta
576640
def diff(self, n):
        
        if os.path.isfile(n[:-4]):
            diff1 = Utils().read_file(n[:-4]).splitlines()
        if os.path.isfile(n):
            diff2 = Utils().read_file(n).splitlines()
        lines, l, c = [], 0, 0
        for a, b in itertools.izip_longest(diff1, diff2):
            l += 1
            if a != b:
                for s1, s2 in itertools.izip_longest(str(a), str(b)):
                    c += 1
                    if s1 != s2:
                        break
                print("@@ -{0},{1} +{2},{3} @@\n".format(l, c, l, c))
                for line in lines[-3:]:
                    print("{0}".format(line))
                if a is None:
                    a = ""
                print("{0}{1}{2}{3}".format(self.red, "-", self.endc, a))
                if b is None:
                    b = ""
                print("{0}{1}{2}{3}".format(self.green, "+", self.endc, b))
                lines = []
                c = 0
            else:
                lines.append(a)
460366
def filesize(fileobj):
    
    current = fileobj.tell()
    fileobj.seek(0, 2)
    end = fileobj.tell()
    fileobj.seek(current)
    return end
1019788
private void resizeTo( int length )
    {
        if ( length <= 0 )
            throw new IllegalArgumentException("length <= 0");
        
        if ( length != buff.length ) {
            int len = ( length > buff.length ) ? buff.length : length;
            //System.out.println("resize:"+length);
            char[] obuff = buff;
            buff = new char[length];
            /*for ( int j = 0; j < len; j++ ) {
                buff[j] = obuff[j];
            }*/
            System.arraycopy(obuff, 0, buff, 0, len);
        }
    }
716972
def resize(self, size):
        
        result = self._client.post('{}/resize'.format(Volume.api_endpoint, model=self,
            data={ "size": size }))

        self._populate(result.json)

        return True
539529
def diff(self, a_ref, target=None, b_ref=None):
    
    result = {}
    diff_dct = self.scm.get_diff_trees(a_ref, b_ref=b_ref)
    result[DIFF_A_REF] = diff_dct[DIFF_A_REF]
    result[DIFF_B_REF] = diff_dct[DIFF_B_REF]
    if diff_dct[DIFF_EQUAL]:
        result[DIFF_EQUAL] = True
        return result
    result[DIFF_LIST] = []
    diff_outs = _get_diff_outs(self, diff_dct)
    if target is None:
        result[DIFF_LIST] = [
            _diff_royal(self, path, diff_outs[path]) for path in diff_outs
        ]
    elif target in diff_outs:
        result[DIFF_LIST] = [_diff_royal(self, target, diff_outs[target])]
    else:
        msg = "Have not found file/directory '{}' in the commits"
        raise FileNotInCommitError(msg.format(target))
    return result
242937
def resize(self, capacity):
        
        count = max(int(capacity), 0) - len(self)

        if count == 0:
            pass
        elif -count == len(self):
            self.clear()
        elif count > 0:
            for i in range(count):
                self.append()
        else:
            for i in range(abs(count)):
                self.pop()
805070
def parse(cls, fileobj):
        

        try:
            length = cls._parse_desc_length_file(fileobj)
        except ValueError as e:
            raise DescriptorError(e)
        pos = fileobj.tell()
        instance = cls(fileobj, length)
        left = length - (fileobj.tell() - pos)
        if left < 0:
            raise DescriptorError("descriptor parsing read too much data")
        fileobj.seek(left, 1)
        return instance