updated for more general use
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
"""Definition of get function."""
|
"""Definition of get function."""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from traceback import print_exc
|
from traceback import print_exc
|
||||||
|
|
||||||
@@ -10,19 +9,22 @@ from minio import Minio
|
|||||||
|
|
||||||
def get(
|
def get(
|
||||||
client: Minio,
|
client: Minio,
|
||||||
|
bucket_name: str,
|
||||||
object_name: str,
|
object_name: str,
|
||||||
) -> BytesIO:
|
) -> BytesIO:
|
||||||
"""Get buffer from bucket in MinIO."""
|
"""Get buffer from bucket in MinIO."""
|
||||||
assert isinstance(client, Minio)
|
assert isinstance(client, Minio)
|
||||||
assert isinstance(object_name, str)
|
assert isinstance(object_name, str)
|
||||||
bucket_name = os.getenv('MINIO_BUCKET_NAME', default='')
|
assert isinstance(bucket_name, str)
|
||||||
# get buffer
|
assert len(bucket_name) > 0
|
||||||
try:
|
try:
|
||||||
|
# make request
|
||||||
response = client.get_object(
|
response = client.get_object(
|
||||||
bucket_name=bucket_name,
|
bucket_name=bucket_name,
|
||||||
object_name=object_name,
|
object_name=object_name,
|
||||||
)
|
)
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
|
# get buffer
|
||||||
buffer = BytesIO()
|
buffer = BytesIO()
|
||||||
chunk_size = 2**14
|
chunk_size = 2**14
|
||||||
while chunk := response.read(chunk_size):
|
while chunk := response.read(chunk_size):
|
||||||
|
|||||||
Reference in New Issue
Block a user