MCPcopy Create free account
hub / github.com/error311/FileRise / openReadStream

Method openReadStream

src/FileRise/Storage/WebDavAdapter.php:186–220  ·  view source on GitHub ↗
(string $path, ?int $length = null, int $offset = 0)

Source from the content-addressed store, hash-verified

184 }
185
186 public function openReadStream(string $path, ?int $length = null, int $offset = 0)
187 {
188 $url = $this->buildUrlForPath($path);
189 if ($url === '') {
190 return false;
191 }
192
193 $headers = [];
194 if ($this->username !== '') {
195 $headers[] = 'Authorization: Basic ' . base64_encode($this->username . ':' . $this->password);
196 }
197 if ($offset > 0 || $length !== null) {
198 $end = ($length !== null && $length > 0) ? ($offset + $length - 1) : '';
199 $headers[] = 'Range: bytes=' . $offset . '-' . $end;
200 }
201 $connectTimeout = $this->timeout > 0 ? min(10, $this->timeout) : 10;
202 $stream = CurlReadStream::open(
203 $url,
204 $headers,
205 $this->verifyTls,
206 $connectTimeout,
207 $this->timeout,
208 function (string $message): void {
209 $this->lastError = $message;
210 }
211 );
212 if ($stream === false) {
213 if ($this->lastError === '') {
214 $this->lastError = 'Unable to open WebDAV read stream.';
215 }
216 return false;
217 }
218
219 return $stream;
220 }
221
222 public function write(string $path, string $data, int $flags = 0): bool
223 {

Callers 9

readMethod · 0.95
signedDownloadMethod · 0.45
downloadSharedFileMethod · 0.45
getDownloadInfoMethod · 0.45
getSharedFileInfoMethod · 0.45

Calls 2

buildUrlForPathMethod · 0.95
openMethod · 0.80

Tested by

no test coverage detected