public function writeBytes($data)
    {
        if ($this->isClosed) {
            // TODO: Should this be an error condition? e.g. BadMethodCallException
            return;
        }

        $bytesRead = 0;

        while ($bytesRead != strlen($data)) {
            $initialBufferLength = strlen($this->buffer);
            $this->buffer .= substr($data, $bytesRead, $this->chunkSize - $initialBufferLength);
            $bytesRead += strlen($this->buffer) - $initialBufferLength;

            if (strlen($this->buffer) == $this->chunkSize) {
                $this->insertChunkFromBuffer();
            }
        }

        return $bytesRead;
    }
public function writeBytes($data)
    {
        if ($this->isClosed) {
            // TODO: Should this be an error condition? e.g. BadMethodCallException
            return;
        }

        $bytesRead = 0;

        while ($bytesRead != strlen($data)) {
            $initialBufferLength = strlen($this->buffer);
            $this->buffer .= substr($data, $bytesRead, $this->chunkSize - $initialBufferLength);
            $bytesRead += strlen($this->buffer) - $initialBufferLength;

            if (strlen($this->buffer) == $this->chunkSize) {
                $this->insertChunkFromBuffer();
            }
        }

        return $bytesRead;
    }
public function writeBytes ( $ data ) { if ( $ this -> isClosed ) { // TODO: Should this be an error condition? e.g. BadMethodCallException return ; } $ bytesRead = 0 ; while ( $ bytesRead != strlen ( $ data ) ) { $ initialBufferLength = strlen ( $ this -> buffer ) ; $ this -> buffer .= substr ( $ data , $ bytesRead , $ this -> chunkSize - $ initialBufferLength ) ; $ bytesRead += strlen ( $ this -> buffer ) - $ initialBufferLength ; if ( strlen ( $ this -> buffer ) == $ this -> chunkSize ) { $ this -> insertChunkFromBuffer ( ) ; } } return $ bytesRead ; }
Inserts binary data into GridFS via chunks.

Data will be buffered internally until chunkSizeBytes are accumulated, at
which point a chunk document will be inserted and the buffer reset.

@param string $data Binary data to write
@return integer
Inserts binary data into GridFS via chunks .