<?php namespace GuzzleHttp\Psr7; use Psr\Http\Message\StreamInterface; /** * Stream decorator that begins dropping data once the size of the underlying * stream becomes too full. */ class DroppingStream implements StreamInterface { use StreamDecoratorTrait; private $maxLength; /** * @param StreamInterface $stream Underlying stream to decorate. * @param int $maxLength Maximum size before dropping data. */ public function __construct(StreamInterface $stream, $maxLength) { $this->stream = $stream; $this->maxLength = $maxLength; } 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)); } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
AppendStream.php | File | 5.37 KB | 0644 |
|
BufferStream.php | File | 2.97 KB | 0644 |
|
CachingStream.php | File | 4.15 KB | 0644 |
|
DroppingStream.php | File | 1.05 KB | 0644 |
|
FnStream.php | File | 3.57 KB | 0644 |
|
InflateStream.php | File | 1.72 KB | 0644 |
|
LazyOpenStream.php | File | 880 B | 0644 |
|
LimitStream.php | File | 4.11 KB | 0644 |
|
MessageTrait.php | File | 4.47 KB | 0644 |
|
MultipartStream.php | File | 4.58 KB | 0644 |
|
NoSeekStream.php | File | 424 B | 0644 |
|
PumpStream.php | File | 3.94 KB | 0644 |
|
Request.php | File | 3.3 KB | 0644 |
|
Response.php | File | 3.97 KB | 0644 |
|
ServerRequest.php | File | 9.19 KB | 0644 |
|
Stream.php | File | 6.59 KB | 0644 |
|
StreamDecoratorTrait.php | File | 3.2 KB | 0644 |
|
StreamWrapper.php | File | 2.74 KB | 0644 |
|
UploadedFile.php | File | 7.37 KB | 0644 |
|
Uri.php | File | 19.35 KB | 0644 |
|
UriNormalizer.php | File | 8.12 KB | 0644 |
|
UriResolver.php | File | 8.57 KB | 0644 |
|
functions.php | File | 23.88 KB | 0644 |
|
functions_include.php | File | 156 B | 0644 |
|