Phalcon\Db\Adapter\MongoDB\GridFS\WritableStream::insertChunks PHP Method

insertChunks() public method

Data will be buffered internally until chunkSizeBytes are accumulated, at which point a chunk's worth of data will be inserted and the buffer reset.
public insertChunks ( string $toWrite ) : integer
$toWrite string Binary data to write
return integer
    public function insertChunks($toWrite)
    {
        if ($this->isClosed) {
            // TODO: Should this be an error condition? e.g. BadMethodCallException
            return;
        }
        $readBytes = 0;
        while ($readBytes != strlen($toWrite)) {
            $addToBuffer = substr($toWrite, $readBytes, $this->chunkSize - $this->bufferLength);
            fwrite($this->buffer, $addToBuffer);
            $readBytes += strlen($addToBuffer);
            $this->bufferLength += strlen($addToBuffer);
            if ($this->bufferLength == $this->chunkSize) {
                rewind($this->buffer);
                $this->insertChunk(stream_get_contents($this->buffer));
                ftruncate($this->buffer, 0);
                $this->bufferLength = 0;
            }
        }
        return $readBytes;
    }