Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a specialized writeStream implementation for s3 external storage #46693

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions apps/files_external/lib/Lib/Storage/AmazonS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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;
Expand Down Expand Up @@ -754,4 +755,24 @@ public function hasUpdated($path, $time) {
return true;
}
}

public function writeStream(string $path, $stream, ?int $size = null): int {
Fixed Show fixed Hide fixed
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;
});
icewind1991 marked this conversation as resolved.
Show resolved Hide resolved
}

if (!is_resource($stream)) {
throw new \InvalidArgumentException("Invalid stream provided");
}

$path = $this->normalizePath($path);
$this->writeObject($path, $stream, $this->mimeDetector->detectPath($path));
Fixed Show fixed Hide fixed
$this->invalidateCache($path);

return $size;
Fixed Show fixed Hide fixed
}
}
Loading