Skip to content

Commit 09374cf

Browse files
icewind1991backportbot[bot]
authored andcommitted
feat: add a specialized writeStream implementation for s3 external storage
Signed-off-by: Robin Appelman <[email protected]>
1 parent a3cb44c commit 09374cf

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

apps/files_external/lib/Lib/Storage/AmazonS3.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
use Aws\S3\Exception\S3Exception;
4444
use Aws\S3\S3Client;
4545
use Icewind\Streams\CallbackWrapper;
46+
use Icewind\Streams\CountWrapper;
4647
use Icewind\Streams\IteratorDirectory;
4748
use OCP\Cache\CappedMemoryCache;
4849
use OC\Files\Cache\CacheEntry;
@@ -790,4 +791,24 @@ public function hasUpdated($path, $time) {
790791
return true;
791792
}
792793
}
794+
795+
public function writeStream(string $path, $stream, ?int $size = null): int {
796+
if ($size === null) {
797+
$size = 0;
798+
// track the number of bytes read from the input stream to return as the number of written bytes.
799+
$stream = CountWrapper::wrap($stream, function (int $writtenSize) use (&$size) {
800+
$size = $writtenSize;
801+
});
802+
}
803+
804+
if (!is_resource($stream)) {
805+
throw new \InvalidArgumentException("Invalid stream provided");
806+
}
807+
808+
$path = $this->normalizePath($path);
809+
$this->writeObject($path, $stream, $this->mimeDetector->detectPath($path));
810+
$this->invalidateCache($path);
811+
812+
return $size;
813+
}
793814
}

0 commit comments

Comments
 (0)