Convert buffer to cdata and check for valid size.
550471
def _check_buffer(self, data, ctype):
        """"""
        assert ctype in _ffi_types.values()
        if not isinstance(data, bytes):
            data = _ffi.from_buffer(data)
        frames, remainder = divmod(len(data),
                                   self.channels * _ffi.sizeof(ctype))
        if remainder:
            raise ValueError("Data size must be a multiple of frame size")
        return data, frames
446873
private void resizeBuffer() {
        if (buffer == null) {
            buffer = new byte[getDefaultBufferSize()];
            pos = 0;
            readPos = 0;
        } else {
            byte[] b = new byte[buffer.length * DEFAULT_BUFFER_RESIZE_FACTOR];
            System.arraycopy(buffer, 0, b, 0, buffer.length);
            buffer = b;
        }
    }
1175348
def _tobinarray_really(self, start, end, pad, size):
        """"""
        if pad is None:
            pad = self.padding
        bin = array('B')
        if self._buf == {} and None in (start, end):
            return bin
        if size is not None and size <= 0:
            raise ValueError("tobinarray: wrong value for size")
        start, end = self._get_start_end(start, end, size)
        for i in range_g(start, end+1):
            bin.append(self._buf.get(i, pad))
        return bin
173480
def convert(self, value, param, ctx):  # pylint: disable=inconsistent-return-statements
        """"""
        matches = MEMORY_RE.match(value.lower())
        if matches is None:
            self.fail('%s is not a valid value for memory amount' % value, param, ctx)
        amount_str, unit = matches.groups()
        amount = int(amount_str)
        if unit in [None, 'm', 'mb']:
            # Assume the user intends gigabytes if they specify a number < 1024
            if amount < 1024:
                return amount * 1024
            else:
                if amount % 1024 != 0:
                    self.fail('%s is not an integer that is divisable by 1024' % value, param, ctx)
                return amount
        elif unit in ['g', 'gb']:
            return amount * 1024
1002078
protected byte[] ensureBufferSize(final int size, final Context context){
        if ((context.buffer == null) || (context.buffer.length < context.pos + size)){
            return resizeBuffer(context);
        }
        return context.buffer;
    }
326730
def num2bytes(value, size):
    """"""
    res = []
    for _ in range(size):
        res.append(value & 0xFF)
        value = value >> 8
    assert value == 0
    return bytes(bytearray(list(reversed(res))))
669042
def to_binary(decimal, length):
        
        b = bitstring.Bits(int=decimal, length=length)
        return b.bin
115183
function insertIntegerToByteArray (number, buffer, from, size) {
  let value = bigInt(number) // convert a number-like object into a big integer

  for (let pos = 0; pos < size; pos++) {
    const divmod = value.divmod(256)
    buffer[from + pos] = divmod.remainder.toJSNumber()
    value = divmod.quotient
  }

  return buffer
}
688207
def size(filename, use_cache_only=False):
    """"""
    filename = unmap_file(filename)
    if filename not in file_cache:
        if not use_cache_only: cache_file(filename)
        if filename not in file_cache:
            return None
        pass
    return len(file_cache[filename].lines['plain'])
81862
def __read_byte_size(decl, attrs):
        """"""
        size = attrs.get(XML_AN_SIZE, 0)
        # Make sure the size is in bytes instead of bits
        decl.byte_size = int(size) / 8
1084632
def read(self,size):
    """"""
    done = 0 #number of bytes that have been read so far
    v = ''
    while True:
      if size-done < len(self._buffer['data']) - self._buffer_pos:
        v +=  self._buffer['data'][self._buffer_pos:self._buffer_pos+(size-done)]
        self._buffer_pos += (size-done)
        #self.pointer += size
        return v
      else: # we need more buffer
        vpart = self._buffer['data'][self._buffer_pos:]
        self._buffer = self._load_block()
        v += vpart
        self._buffer_pos = 0
        if len(self._buffer['data'])==0: return v
        done += len(vpart)
885215
def matchBytes(self, bytes):
        """"""
        p = self.position
        data = self[p:p + len(bytes)]
        rv = data.startswith(bytes)
        if rv:
            self.position += len(bytes)
        return rv
281482
def read(self, size=None):  # pylint: disable=invalid-name
        """"""
        if size is None or size < 0:
            raise exceptions.NotYetImplementedError(
                'Illegal read of size %s requested on BufferedStream. '
                'Wrapped stream %s is at position %s-%s, '
                '%s bytes remaining.' %
                (size, self.__stream, self.__start_pos, self.__end_pos,
                 self._bytes_remaining))

        data = ''
        if self._bytes_remaining:
            size = min(size, self._bytes_remaining)
            data = self.__buffered_data[
                self.__buffer_pos:self.__buffer_pos + size]
            self.__buffer_pos += size
        return data
309077
def convert_bytes(b):
    ''''''
    if b is None:
        return '#NA'
    for s in reversed(memory_symbols):
        if b >= memory_size[s]:
            value = float(b) / memory_size[s]
            return '%.1f%sB' % (value, s)
    return "%sB" % b
190310
function toArrayBuffer(buf) {
  if (buf.byteLength === buf.buffer.byteLength) {
    return buf.buffer;
  }

  return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
}
103570
function checkSum(buffer, offset, length) {
            if (buffer instanceof ArrayBuffer) {
                return checkSumArrayBuffer(buffer, offset, length);
            }
            else if (buffer instanceof Array) {
                return checkSumArray(buffer, offset, length);
            }

            throw new Error('not support checksum buffer type');
        }
1272834
def diskdata():
    """"""
    p = os.popen("/bin/df -l -P")
    ddata = {}
    tsize = 0
    for line in p.readlines():
        d = line.split()
        if ("/dev/sd" in d[0] or "/dev/hd" in d[0] or "/dev/mapper" in d[0]):
            tsize = tsize + int(d[1])
    ddata["Disk_GB"] = int(tsize)/1000000
    p.close()
    return ddata