PluginProbe
Media Cloud Sync / 1.0.3
Media Cloud Sync v1.0.3
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
media-cloud-sync / includes / sdk / s3 / GuzzleHttp / Psr7 / DroppingStream.php

DroppingStream.php in Media Cloud Sync 1.0.3, at includes/sdk/s3/GuzzleHttp/Psr7/DroppingStream.php

39 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7;
4
5 use Dudlewebs\WPMCS\s3\Psr\Http\Message\StreamInterface;
6 /**
7 * Stream decorator that begins dropping data once the size of the underlying
8 * stream becomes too full.
9 *
10 * @final
11 */
12 class DroppingStream implements StreamInterface
13 {
14 use StreamDecoratorTrait;
15 private $maxLength;
16 /**
17 * @param StreamInterface $stream Underlying stream to decorate.
18 * @param int $maxLength Maximum size before dropping data.
19 */
20 public function __construct(StreamInterface $stream, $maxLength)
21 {
22 $this->stream = $stream;
23 $this->maxLength = $maxLength;
24 }
25 public function write($string)
26 {
27 $diff = $this->maxLength - $this->stream->getSize();
28 // Begin returning 0 when the underlying stream is too large.
29 if ($diff <= 0) {
30 return 0;
31 }
32 // Write the stream or a subset of the stream if needed.
33 if (\strlen($string) < $diff) {
34 return $this->stream->write($string);
35 }
36 return $this->stream->write(\substr($string, 0, $diff));
37 }
38 }
39