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

Method writeStream

src/FileRise/Storage/WebDavAdapter.php:235–280  ·  view source on GitHub ↗
(string $path, $stream, ?int $length = null, ?string $mimeType = null)

Source from the content-addressed store, hash-verified

233 }
234
235 public function writeStream(string $path, $stream, ?int $length = null, ?string $mimeType = null): bool
236 {
237 if (!is_resource($stream)) {
238 return false;
239 }
240 if (!$this->ensureParentExists($path)) {
241 return false;
242 }
243 $url = $this->buildUrlForPath($path);
244 if ($url === '') {
245 return false;
246 }
247 $headers = [];
248 if ($mimeType) {
249 $headers['Content-Type'] = $mimeType;
250 }
251 $meta = @stream_get_meta_data($stream);
252 $seekable = is_array($meta) && !empty($meta['seekable']);
253 if ($length === null) {
254 $stat = @fstat($stream);
255 if (is_array($stat) && isset($stat['size'])) {
256 $length = (int)$stat['size'];
257 }
258 }
259 if ($length !== null && $length >= 0) {
260 $headers['Content-Length'] = (string)$length;
261 }
262 if ($seekable) {
263 @rewind($stream);
264 }
265 $status = $this->request('PUT', $url, $stream, $headers);
266 if ($status >= 200 && $status < 300) {
267 return true;
268 }
269
270 if ($seekable && $length !== null && $length <= self::WRITE_FALLBACK_MAX_BYTES) {
271 @rewind($stream);
272 $data = stream_get_contents($stream);
273 if ($data !== false) {
274 $status = $this->request('PUT', $url, $data, $headers);
275 return $status >= 200 && $status < 300;
276 }
277 }
278
279 return false;
280 }
281
282 public function move(string $from, string $to): bool
283 {

Callers 5

handleUploadMethod · 0.45
saveFileMethod · 0.45
uploadToSharedFolderMethod · 0.45

Calls 3

ensureParentExistsMethod · 0.95
buildUrlForPathMethod · 0.95
requestMethod · 0.95

Tested by

no test coverage detected