Write a chunk::
        chunk-size(hex) CRLF
        chunk-data CRLF
    If the size is 0, this is the last chunk, and an extra CRLF is appended.
180199
def chunk_encoding(chunks, chunk):
    '''
    '''
    chunks.extend(("%X\r\n" % len(chunk)).encode('utf-8'))
    chunks.extend(chunk)
    chunks.extend(CRLF)
761706
def multiple_chunks(self, chunk_size=None):
        
        if not chunk_size:
            chunk_size = self.DEFAULT_CHUNK_SIZE
        return self.size > chunk_size
1187954
def _file_chunks(self, data, chunk_size):
        
        for i in xrange(0, len(data), chunk_size):
            yield self.compressor(data[i:i+chunk_size])
939462
def _request_new_chunk(self):
        
        # Figure out the length of the next request
        new_len = self._bytes_left
        if new_len > _ReadRequest.MAX_DATA_LENGTH:
            new_len = _ReadRequest.MAX_DATA_LENGTH

        logger.debug('Requesting new chunk of {}bytes at 0x{:X}'.format(
            new_len, self._current_addr))

        # Request the data for the next address
        pk = CRTPPacket()
        pk.set_header(CRTPPort.MEM, CHAN_READ)
        pk.data = struct.pack('<BIB', self.mem.id, self._current_addr, new_len)
        reply = struct.unpack('<BBBBB', pk.data[:-1])
        self.cf.send_packet(pk, expected_reply=reply, timeout=1)
863824
function _bst(chunk, type) {
  // we should have already read the chunk
  var len = this._int(chunk, type), buf;
  if(!isNaN(len)) {
    // read an integer less than zero, treat as null
    if(len < 0) return null;
    // read in the entire bulk string and swallow the crlf
    if((chunk.length - this._offset) >= len + 2) {
      buf = chunk.slice(this._offset, this._offset + len);
      this._offset += (len + 2);
      //this._buffer = this._buffer.slice(this._offset, this._buffer.length);
      //console.dir(buf);
      return this.buffers ? buf : '' + buf;
    }else{
      this._wait();
    }
  }
}
1059424
def write_crc32(fo, bytes):
    """"""
    data = crc32(bytes) & 0xFFFFFFFF
    fo.write(pack('>I', data))
124458
def _chunk_actions(actions, chunk_size, max_chunk_bytes, serializer):
    
    bulk_actions, bulk_data = [], []
    size, action_count = 0, 0
    for action, data in actions:
        raw_data, raw_action = data, action
        action = serializer.dumps(action)
        # +1 to account for the trailing new line character
        cur_size = len(action.encode("utf-8")) + 1

        if data is not None:
            data = serializer.dumps(data)
            cur_size += len(data.encode("utf-8")) + 1

        # full chunk, send it and start a new one
        if bulk_actions and (
            size + cur_size > max_chunk_bytes or action_count == chunk_size
        ):
            yield bulk_data, bulk_actions
            bulk_actions, bulk_data = [], []
            size, action_count = 0, 0

        bulk_actions.append(action)
        if data is not None:
            bulk_actions.append(data)
            bulk_data.append((raw_action, raw_data))
        else:
            bulk_data.append((raw_action,))

        size += cur_size
        action_count += 1

    if bulk_actions:
        yield bulk_data, bulk_actions
1199140
def chunks(stream, chunk_size, output_type=tuple):
    '''  '''
    assert iterable(stream), 'chunks needs stream to be iterable'
    assert (isinstance(chunk_size, int) and chunk_size > 0) or callable(chunk_size), 'chunks needs chunk_size to be a positive int or callable'
    assert callable(output_type), 'chunks needs output_type to be callable'
    if callable(chunk_size):
        ''' chunk_size is acting as a separator function '''
        for chunk in chunk_on(stream, chunk_size, output_type):
            yield chunk
    else:
        it = iter(stream)
        marker = object()
        iters = [it] * chunk_size
        pipeline = apply_to_last(
           zip_longest(*iters, fillvalue=marker),
           lambda last_chunk: tuple(i for i in last_chunk if i is not marker)
        )
        if output_type is not tuple:
            pipeline = map(output_type, pipeline)
        for chunk in pipeline:
            yield chunk
468545
async def write(self, chunk: bytes,
                    *, drain: bool=True, LIMIT: int=0x10000) -> None:
        
        if self._on_chunk_sent is not None:
            await self._on_chunk_sent(chunk)

        if self._compress is not None:
            chunk = self._compress.compress(chunk)
            if not chunk:
                return

        if self.length is not None:
            chunk_len = len(chunk)
            if self.length >= chunk_len:
                self.length = self.length - chunk_len
            else:
                chunk = chunk[:self.length]
                self.length = 0
                if not chunk:
                    return

        if chunk:
            if self.chunked:
                chunk_len_pre = ('%x\r\n' % len(chunk)).encode('ascii')
                chunk = chunk_len_pre + chunk + b'\r\n'

            self._write(chunk)

            if self.buffer_size > LIMIT and drain:
                self.buffer_size = 0
                await self.drain()
618221
def chunks(data, chunk_size):
    
    for i in xrange(0, len(data), chunk_size):
        yield data[i:i+chunk_size]
990554
def file_crc32(filename, chunksize=_CHUNKSIZE):
    

    check = 0
    with open(filename, 'rb') as fd:
        for data in iter(lambda: fd.read(chunksize), ""):
            check = crc32(data, check)
    return check
77740
def write_chunk(cls, sock, chunk_type, payload=b''):
    """"""
    chunk = cls.construct_chunk(chunk_type, payload)
    sock.sendall(chunk)
341329
function chunkLength (chunk, encoding) {
  if (!chunk) {
    return 0
  }

  return !Buffer.isBuffer(chunk)
    ? Buffer.byteLength(chunk, encoding)
    : chunk.length
}
225844
def write_chunks(out, chunks):
    """"""

    out.write(_signature)
    for chunk in chunks:
        write_chunk(out, *chunk)
157759
def make_chunk(chunk_type, chunk_data):
	
	out = struct.pack("!I", len(chunk_data))
	chunk_data = chunk_type.encode("latin-1") + chunk_data
	out += chunk_data + struct.pack("!I", binascii.crc32(chunk_data) & 0xffffffff)
	return out
132057
protected void wrapBuffer()
        throws IOException
    {
        // Handle chunking
        int size=size();
        if (_chunking && size()>0)
        {
            prewrite(__CRLF,0,__CRLF.length);
            while (size>0)
            {
                int d=size%16;
                if (d<=9)
                    prewrite('0'+d);
                else
                    prewrite('a'-10+d);
                size=size/16;
            }
            postwrite(__CRLF,0,__CRLF.length);
        }
        
        // Complete it if we must.
        if (_complete && !_completed)
        {
            _completed=true;
            if (_chunking)
                postwrite(__CHUNK_EOF,0,__CHUNK_EOF.length);
        }
    }
133716
def determine_num_chunks(chunk_size, file_size):
        
        if file_size == 0:
            return 1
        return int(math.ceil(float(file_size) / float(chunk_size)))