Skip to content

Commit

Permalink
[GCS] Add option to stream reads
Browse files Browse the repository at this point in the history
  • Loading branch information
rickclephas committed Jan 26, 2025
1 parent 704c10b commit 78b0018
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/GoogleCloudStorage/GoogleCloudStorageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public function __construct(
string $prefix = '',
?VisibilityHandler $visibilityHandler = null,
private string $defaultVisibility = Visibility::PRIVATE,
?MimeTypeDetector $mimeTypeDetector = null
?MimeTypeDetector $mimeTypeDetector = null,
private bool $streamReads = false,
) {
$this->prefixer = new PathPrefixer($prefix);
$this->visibilityHandler = $visibilityHandler ?? new PortableVisibilityHandler();
Expand Down Expand Up @@ -170,9 +171,13 @@ public function read(string $path): string
public function readStream(string $path)
{
$prefixedPath = $this->prefixer->prefixPath($path);
$options = [];
if ($this->streamReads) {
$options['restOptions']['stream'] = true;
}

try {
$stream = $this->bucket->object($prefixedPath)->downloadAsStream()->detach();
$stream = $this->bucket->object($prefixedPath)->downloadAsStream($options)->detach();
} catch (Throwable $exception) {
throw UnableToReadFile::fromLocation($path, $exception->getMessage(), $exception);
}
Expand Down

0 comments on commit 78b0018

Please sign in to comment.