Skip to content

Commit e96dfac

Browse files
authored
Merge pull request #1848 from rickclephas/feature/gcs-streaming-reads
[GCS] Add option to stream reads
2 parents a8d9ba9 + 91ecc62 commit e96dfac

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/GoogleCloudStorage/GoogleCloudStorageAdapter.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public function __construct(
6060
string $prefix = '',
6161
?VisibilityHandler $visibilityHandler = null,
6262
private string $defaultVisibility = Visibility::PRIVATE,
63-
?MimeTypeDetector $mimeTypeDetector = null
63+
?MimeTypeDetector $mimeTypeDetector = null,
64+
private bool $streamReads = false,
6465
) {
6566
$this->prefixer = new PathPrefixer($prefix);
6667
$this->visibilityHandler = $visibilityHandler ?? new PortableVisibilityHandler();
@@ -170,9 +171,13 @@ public function read(string $path): string
170171
public function readStream(string $path)
171172
{
172173
$prefixedPath = $this->prefixer->prefixPath($path);
174+
$options = [];
175+
if ($this->streamReads) {
176+
$options['restOptions']['stream'] = true;
177+
}
173178

174179
try {
175-
$stream = $this->bucket->object($prefixedPath)->downloadAsStream()->detach();
180+
$stream = $this->bucket->object($prefixedPath)->downloadAsStream($options)->detach();
176181
} catch (Throwable $exception) {
177182
throw UnableToReadFile::fromLocation($path, $exception->getMessage(), $exception);
178183
}

0 commit comments

Comments
 (0)