From e21ddcfeb025dacee9de1b712627fe03a32d0f0d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 22 Jul 2024 21:51:34 +0200 Subject: [PATCH] feat: add a specialized writeStream implementation for s3 external storage Signed-off-by: Robin Appelman --- .../lib/Lib/Storage/AmazonS3.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php index 8e2a6b8ea12e3..0d1010a4cfbe9 100644 --- a/apps/files_external/lib/Lib/Storage/AmazonS3.php +++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php @@ -43,6 +43,7 @@ use Aws\S3\Exception\S3Exception; use Aws\S3\S3Client; use Icewind\Streams\CallbackWrapper; +use Icewind\Streams\CountWrapper; use Icewind\Streams\IteratorDirectory; use OCP\Cache\CappedMemoryCache; use OC\Files\Cache\CacheEntry; @@ -790,4 +791,24 @@ public function hasUpdated($path, $time) { return true; } } + + public function writeStream(string $path, $stream, ?int $size = null): int { + if ($size === null) { + $size = 0; + // track the number of bytes read from the input stream to return as the number of written bytes. + $stream = CountWrapper::wrap($stream, function (int $writtenSize) use (&$size) { + $size = $writtenSize; + }); + } + + if (!is_resource($stream)) { + throw new \InvalidArgumentException("Invalid stream provided"); + } + + $path = $this->normalizePath($path); + $this->writeObject($path, $stream, $this->mimeDetector->detectPath($path)); + $this->invalidateCache($path); + + return $size; + } }