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;
}