Send the chunk size
187936
private void sendChunkSize() {
        if (chunkSizeSent.compareAndSet(false, true)) {
            log.debug("Sending chunk size: {}", chunkSize);
            ChunkSize chunkSizeMsg = new ChunkSize(chunkSize);
            conn.getChannel((byte) 2).write(chunkSizeMsg);
        }
    }
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()
323778
public function sendChunk($req, $chunk)
    {
        $packet = "\x01" // protocol version
            . "\x06" // record type (STDOUT)
            . pack(
                'nn',
                $req->attrs->id,
                mb_orig_strlen($chunk)
            ) // id, content length
            . "\x00" // padding length
            . "\x00";// reserved

        return $this->write($packet) && $this->write($chunk); // content
    }
638283
def send_pgrp(cls, sock, pgrp):
    """"""
    assert(isinstance(pgrp, IntegerForPid) and pgrp < 0)
    encoded_int = cls.encode_int(pgrp)
    cls.write_chunk(sock, ChunkType.PGRP, encoded_int)
892721
def write(self, chunk):
        
        if not self.started_response:
            raise AssertionError('WSGI write called before start_response.')

        chunklen = len(chunk)
        rbo = self.remaining_bytes_out
        if rbo is not None and chunklen > rbo:
            if not self.req.sent_headers:
                # Whew. We can send a 500 to the client.
                self.req.simple_response(
                    '500 Internal Server Error',
                    'The requested resource returned more bytes than the '
                    'declared Content-Length.',
                )
            else:
                # Dang. We have probably already sent data. Truncate the chunk
                # to fit (so the client doesn't hang) and raise an error later.
                chunk = chunk[:rbo]

        self.req.ensure_headers_sent()

        self.req.write(chunk)

        if rbo is not None:
            rbo -= chunklen
            if rbo < 0:
                raise ValueError(
                    'Response body exceeds the declared Content-Length.',
                )
46223
protected function sendContent()
    {
        $body = $this->getBody();
        if (!$body->isReadable()) {
            throw new \RuntimeException('Unable to send content: body stream is not readable.');
        }

        set_time_limit(0); // Reset time limit for big files
        $chunkSize = 8 * 1024 * 1024; // 8MB per chunk

        if (is_array($this->bodyRange)) {
            [$begin, $end] = $this->bodyRange;

            if (!$body->isSeekable()) {
                throw new \RuntimeException('Unable to send content in range: body stream is not seekable.');
            }

            $body->seek($begin);
            while (!$body->eof() && ($pos = $body->tell()) <= $end) {
                if ($pos + $chunkSize > $end) {
                    $chunkSize = $end - $pos + 1;
                }
                echo $body->read($chunkSize);
                flush(); // Free up memory. Otherwise large files will trigger PHP's memory limit.
            }
            $body->close();
        } else {
            if ($body->isSeekable()) {
                $body->seek(0);
            }
            while (!$body->eof()) {
                echo $body->read($chunkSize);
                flush(); // Free up memory. Otherwise large files will trigger PHP's memory limit.
            }
            $body->close();
            return;
        }
    }
372753
def _chunk_actions(actions, chunk_size, max_chunk_bytes, serializer):
    
    bulk_actions = []
    size, action_count = 0, 0
    for action, data in actions:
        action = serializer.dumps(action)
        cur_size = len(action) + 1

        if data is not None:
            data = serializer.dumps(data)
            cur_size += len(data) + 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_actions
            bulk_actions = []
            size, action_count = 0, 0

        bulk_actions.append(action)
        if data is not None:
            bulk_actions.append(data)
        size += cur_size
        action_count += 1

    if bulk_actions:
        yield bulk_actions
1157580
def stream_download(self, chunk_size: Optional[int] = None, callback: Optional[Callable] = None) -> AsyncIterator[bytes]:
        
        chunk_size = chunk_size or CONTENT_CHUNK_SIZE
        async def async_gen(resp):
            while True:
                chunk = await resp.content.read(chunk_size)
                if not chunk:
                    break
                callback(chunk, resp)
        return async_gen(self.internal_response)
779705
def split_size(size):
    ''''''
    rem = size % CHUNK_SIZE
    if rem == 0:
        cnt = size // CHUNK_SIZE
    else:
        cnt = size // CHUNK_SIZE + 1

    chunks = []
    for i in range(cnt):
        pos = i * CHUNK_SIZE
        if i == cnt - 1:
            disp = size - pos
        else:
            disp = CHUNK_SIZE
        chunks.append((pos, disp))
    return chunks
1125793
def insert_chunk(self, id_):
        """"""

        assert_valid_chunk_id(id_)

        self.__fileobj.seek(self.__next_offset)
        self.__fileobj.write(pack('>4si', id_.ljust(4).encode('ascii'), 0))
        self.__fileobj.seek(self.__next_offset)
        chunk = IFFChunk(self.__fileobj, self[u'FORM'])
        self[u'FORM']._update_size(self[u'FORM'].data_size + chunk.size)

        self.__chunks[id_] = chunk
        self.__next_offset = chunk.offset + chunk.size
783420
def send(self, data: bytes = b""):
        
        self.input.extend(data)
        self._process()
769331
def send_bytes(self):
        """"""
        data = b''.join(self.bytes_to_send)
        self.bytes_to_send = []
        return data
973341
def chunk_data(payload, max_size)
      total = payload.bytesize
      cursor = 0
      while (total - cursor) > max_size
        yield payload.byteslice(cursor, max_size)
        cursor += max_size
      end
      payload.byteslice(cursor, total - cursor)
    end
963565
def streamWrite(self, size):
        
        size = int(size)
        if size == 0:
            self._close()
            return

        self._sendResult(dict(message="writing...", stream=True, size=size))
        data = sys.stdin.read(size)
        self.stream.write(data)
77740
def write_chunk(cls, sock, chunk_type, payload=b''):
    """"""
    chunk = cls.construct_chunk(chunk_type, payload)
    sock.sendall(chunk)
1144933
def stream(self, url, params=None, chunk_size=64*1024):
        ''
        r = self.request(url, params=params)
        for chunk in r.iter_content(chunk_size):
            yield chunk
871617
def transfer(sendContext, receiveContext, chunkSize):
    
    try:
        chunkSize = receiveContext.chunkSize
    except AttributeError:
        pass

    if sendContext is not None and receiveContext is not None:
        with receiveContext as writer:
            # Open reader after writer,
            # so any raised errors will abort write before writer closes.
            with sendContext as reader:
                checkBefore = None
                if hasattr(writer, 'skipChunk'):
                    checkBefore = hasattr(reader, 'checkSum')

                while True:
                    if checkBefore is True:
                        (size, checkSum) = reader.checkSum(chunkSize)

                        if writer.skipChunk(size, checkSum):
                            reader.seek(size, io.SEEK_CUR)
                            continue

                    data = reader.read(chunkSize)
                    if len(data) == 0:
                        break

                    if checkBefore is False:
                        checkSum = hashlib.md5(data).hexdigest()

                        if writer.skipChunk(len(data), checkSum, data):
                            continue

                    writer.write(data)