You are here

public function DroppingStream::write in Lockr 7.3

Write data to the stream.

Parameters

string $string The string that is to be written.:

Return value

int Returns the number of bytes written to the stream.

Throws

\RuntimeException on failure.

Overrides StreamDecoratorTrait::write

File

vendor/guzzlehttp/psr7/src/DroppingStream.php, line 26

Class

DroppingStream
Stream decorator that begins dropping data once the size of the underlying stream becomes too full.

Namespace

GuzzleHttp\Psr7

Code

public function write($string) {
  $diff = $this->maxLength - $this->stream
    ->getSize();

  // Begin returning 0 when the underlying stream is too large.
  if ($diff <= 0) {
    return 0;
  }

  // Write the stream or a subset of the stream if needed.
  if (strlen($string) < $diff) {
    return $this->stream
      ->write($string);
  }
  return $this->stream
    ->write(substr($string, 0, $diff));
}