使用最新的 azure.storage.blob (12.4.0) python 库,我需要在 blob 上打开一个流,而不将其完全下载到内存中。
我有 hdf5 文件存储在存储帐户中,使用 h5py (2.10.0) 我需要提取一些信息,读取数据而不将文件加载到内存中。这些文件可以包含许多千兆字节的数据。
container_client = blob_service_client.get_container_client('sample')
blob = container_client.get_blob_client('SampleHdF5.hdf5')
stream = BytesIO()
downloader = blob.download_blob()
# download the entire file in memory here
# file can be many giga bytes! Big problem
downloader.readinto(stream)
# works fine to open the stream and read data
f = h5py.File(stream, 'r')
也许 Azure 上还有另一种服务更适合此类需求。
get_blob_to_stream
可以与azure.storage.blob.baseblobservice
指的是here https://azure-storage.readthedocs.io/ref/azure.storage.blob.baseblobservice.html#azure.storage.blob.baseblobservice.BaseBlobService.get_blob_to_stream。有我用过的包。
from azure.storage.blob.baseblobservice import BaseBlobService
import io
connection_string = ""
container_name = ""
blob_name = ""
blob_service = BaseBlobService(connection_string=connection_string)
with io.BytesIO() as input_io:
blob_service.get_blob_to_stream(container_name=container_name, blob_name=blob_name, stream=input_io)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)