【发布时间】:2020-08-24 10:16:03
【问题描述】:
使用最新的 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 上有另一种更适合这种需求的服务。
【问题讨论】:
-
您的意思是让 blob 流式传输吗?如果是这样,此代码将有所帮助:
with io.BytesIO() as input_io: blob_service.get_blob_to_stream(container_name=container_name, blob_name=blob.name, stream=input_io) -
get_blob_to_stream 接缝在 azure.storage.blob.baseblobservice 的旧版本中可用,该版本不再可用。也许我错过了什么!
标签: python hdf5 azure-storage-account