updated for more general use

This commit is contained in:
brian
2024-10-25 17:19:15 +00:00
parent 42400d6f32
commit bdf3e73ba9
+5 -3
View File
@@ -1,7 +1,6 @@
"""Definition of get function."""
import logging
import os
from io import BytesIO
from traceback import print_exc
@@ -10,19 +9,22 @@ from minio import Minio
def get(
client: Minio,
bucket_name: str,
object_name: str,
) -> BytesIO:
"""Get buffer from bucket in MinIO."""
assert isinstance(client, Minio)
assert isinstance(object_name, str)
bucket_name = os.getenv('MINIO_BUCKET_NAME', default='')
# get buffer
assert isinstance(bucket_name, str)
assert len(bucket_name) > 0
try:
# make request
response = client.get_object(
bucket_name=bucket_name,
object_name=object_name,
)
assert response.status == 200
# get buffer
buffer = BytesIO()
chunk_size = 2**14
while chunk := response.read(chunk_size):