feat: add a specialized writeStream implementation for s3 external storage

Signed-off-by: Robin Appelman <robin@icewind.nl>
pull/46743/head
Robin Appelman 2024-07-22 21:51:34 +07:00 committed by backportbot[bot]
parent 4ec3ccd6aa
commit ed58026e4d
1 changed files with 21 additions and 0 deletions

@ -41,6 +41,7 @@ namespace OCA\Files_External\Lib\Storage;
use Aws\S3\Exception\S3Exception;
use Icewind\Streams\CallbackWrapper;
use Icewind\Streams\CountWrapper;
use Icewind\Streams\IteratorDirectory;
use OC\Files\Cache\CacheEntry;
use OC\Files\ObjectStore\S3ConnectionTrait;
@ -787,4 +788,24 @@ class AmazonS3 extends \OC\Files\Storage\Common {
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;
}
}