From 91ecc62cd11c26de8b4426c64dda20f017e39ba5 Mon Sep 17 00:00:00 2001 From: Rick Clephas Date: Sun, 26 Jan 2025 14:40:30 +0100 Subject: [PATCH] [GCS] Add option to stream reads --- src/GoogleCloudStorage/GoogleCloudStorageAdapter.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php b/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php index b180f72b5..a8b1b5a03 100644 --- a/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php +++ b/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php @@ -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(); @@ -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); }