original_string: 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;
      }
code: 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;
      }
code_tokens: 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 ; }
docstring: 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
docstring_tokens: Inserts binary data into GridFS via chunks .