PluginProbe
Media Cloud Sync / 1.2.6
Media Cloud Sync v1.2.6
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 / BufferStream.php

BufferStream.php in Media Cloud Sync 1.2.6, at includes/sdk/s3/GuzzleHttp/Psr7/BufferStream.php

119 lines 3.0 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 * Provides a buffer stream that can be written to to fill a buffer, and read
8 * from to remove bytes from the buffer.
9 *
10 * This stream returns a "hwm" metadata value that tells upstream consumers
11 * what the configured high water mark of the stream is, or the maximum
12 * preferred size of the buffer.
13 *
14 * @final
15 */
16 class BufferStream implements StreamInterface
17 {
18 private $hwm;
19 private $buffer = '';
20 /**
21 * @param int $hwm High water mark, representing the preferred maximum
22 * buffer size. If the size of the buffer exceeds the high
23 * water mark, then calls to write will continue to succeed
24 * but will return false to inform writers to slow down
25 * until the buffer has been drained by reading from it.
26 */
27 public function __construct($hwm = 16384)
28 {
29 $this->hwm = $hwm;
30 }
31 public function __toString()
32 {
33 return $this->getContents();
34 }
35 public function getContents()
36 {
37 $buffer = $this->buffer;
38 $this->buffer = '';
39 return $buffer;
40 }
41 public function close()
42 {
43 $this->buffer = '';
44 }
45 public function detach()
46 {
47 $this->close();
48 return null;
49 }
50 public function getSize()
51 {
52 return \strlen($this->buffer);
53 }
54 public function isReadable()
55 {
56 return \true;
57 }
58 public function isWritable()
59 {
60 return \true;
61 }
62 public function isSeekable()
63 {
64 return \false;
65 }
66 public function rewind()
67 {
68 $this->seek(0);
69 }
70 public function seek($offset, $whence = \SEEK_SET)
71 {
72 throw new \RuntimeException('Cannot seek a BufferStream');
73 }
74 public function eof()
75 {
76 return \strlen($this->buffer) === 0;
77 }
78 public function tell()
79 {
80 throw new \RuntimeException('Cannot determine the position of a BufferStream');
81 }
82 /**
83 * Reads data from the buffer.
84 */
85 public function read($length)
86 {
87 $currentLength = \strlen($this->buffer);
88 if ($length >= $currentLength) {
89 // No need to slice the buffer because we don't have enough data.
90 $result = $this->buffer;
91 $this->buffer = '';
92 } else {
93 // Slice up the result to provide a subset of the buffer.
94 $result = \substr($this->buffer, 0, $length);
95 $this->buffer = \substr($this->buffer, $length);
96 }
97 return $result;
98 }
99 /**
100 * Writes data to the buffer.
101 */
102 public function write($string)
103 {
104 $this->buffer .= $string;
105 // TODO: What should happen here?
106 if (\strlen($this->buffer) >= $this->hwm) {
107 return \false;
108 }
109 return \strlen($string);
110 }
111 public function getMetadata($key = null)
112 {
113 if ($key == 'hwm') {
114 return $this->hwm;
115 }
116 return $key ? null : [];
117 }
118 }
119