24 $this->remoteStream =
$body;
25 $this->body =
new EntityBody(fopen(
'php://temp',
'r+'));
37 $pos = $this->
ftell();
42 $str .= $this->
read(16384);
52 return max($this->body->getSize(), $this->remoteStream->getSize());
59 public function seek($offset, $whence = SEEK_SET)
61 if ($whence == SEEK_SET) {
63 } elseif ($whence == SEEK_CUR) {
64 $byte = $offset + $this->
ftell();
66 throw new RuntimeException(__CLASS__ .
' supports only SEEK_SET and SEEK_CUR seek operations');
70 if ($byte > $this->body->getSize()) {
71 throw new RuntimeException(
72 "Cannot seek to byte {$byte} when the buffered stream only contains {$this->body->getSize()} bytes"
76 return $this->body->seek($byte);
81 return $this->
seek(0);
91 throw new RuntimeException(__CLASS__ .
' does not support custom stream rewind functions');
94 public function read($length)
97 $data = $this->body->read($length);
98 $remaining = $length - strlen($data);
105 $remoteData = $this->remoteStream->read($remaining + $this->skipReadBytes);
107 if ($this->skipReadBytes) {
108 $len = strlen($remoteData);
109 $remoteData = substr($remoteData, $this->skipReadBytes);
110 $this->skipReadBytes = max(0, $this->skipReadBytes - $len);
113 $data .= $remoteData;
114 $this->body->write($remoteData);
120 public function write($string)
124 $overflow = (strlen($string) + $this->
ftell()) - $this->remoteStream->ftell();
126 $this->skipReadBytes += $overflow;
129 return $this->body->write($string);
136 public function readLine($maxLength =
null)
141 $byte = $this->
read(1);
144 if ($byte == PHP_EOL || ++$size == $maxLength - 1) {
154 return $this->body->isConsumed() && $this->remoteStream->isConsumed();
160 public function close()
162 return $this->remoteStream->close() && $this->body->close();
165 public function setStream($stream, $size = 0)
167 $this->remoteStream->setStream($stream, $size);
172 return $this->remoteStream->getContentType();
177 return $this->remoteStream->getContentEncoding();
182 return $this->remoteStream->getMetaData($key);
187 return $this->remoteStream->getStream();
192 return $this->remoteStream->getWrapper();
197 return $this->remoteStream->getWrapperData();
202 return $this->remoteStream->getStreamType();
207 return $this->remoteStream->getUri();
216 return $this->remoteStream->getCustomData($key);
225 $this->remoteStream->setCustomData($key, $value);