43 public function __construct(callable $source, array $options = [])
45 $this->source = $source;
46 $this->size = isset($options[
'size']) ? $options[
'size'] :
null;
47 $this->metadata = isset($options[
'metadata']) ? $options[
'metadata'] : [];
55 }
catch (\Exception $e) {
60 public function close()
67 $this->tellPos =
false;
76 public function tell()
78 return $this->tellPos;
83 return !$this->source;
96 public function seek($offset, $whence = SEEK_SET)
98 throw new \RuntimeException(
'Cannot seek a PumpStream');
108 throw new \RuntimeException(
'Cannot write to a PumpStream');
118 $data = $this->buffer->read($length);
119 $readLen = strlen($data);
120 $this->tellPos += $readLen;
121 $remaining = $length - $readLen;
124 $this->pump($remaining);
125 $data .= $this->buffer->read($remaining);
126 $this->tellPos += strlen($data) - $readLen;
135 while (!$this->
eof()) {
136 $result .= $this->
read(1000000);
145 return $this->metadata;
148 return isset($this->metadata[$key]) ? $this->metadata[$key] :
null;
151 private function pump($length)
155 $data = call_user_func($this->source, $length);
156 if ($data ===
false || $data ===
null) {
157 $this->source =
null;
160 $this->buffer->write($data);
161 $length -= strlen($data);
162 }
while ($length > 0);