refactor: update load_stream method to directly yield file chunks (#9806)

This commit is contained in:
zhuhao 2024-10-25 10:11:25 +08:00 • committed by GitHub
commit 5bf31e7a86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 48 additions and 83 deletions

View file

@ -39,14 +39,11 @@ class GoogleCloudStorage(BaseStorage):
return data
def load_stream(self, filename: str) -> Generator:
def generate(filename: str = filename) -> Generator:
bucket = self.client.get_bucket(self.bucket_name)
blob = bucket.get_blob(filename)
with blob.open(mode="rb") as blob_stream:
while chunk := blob_stream.read(4096):
yield chunk
return generate()
bucket = self.client.get_bucket(self.bucket_name)
blob = bucket.get_blob(filename)
with blob.open(mode="rb") as blob_stream:
while chunk := blob_stream.read(4096):
yield chunk
def download(self, filename, target_filepath):
bucket = self.client.get_bucket(self.bucket_name)