h5py可以从内存中的字节数组加载文件吗?(Can h5py load a file from a byte array in memory?)

系统教程 行业动态 更新时间:2024-06-14 17:02:18
h5py可以从内存中的字节数组加载文件吗?(Can h5py load a file from a byte array in memory?)

我的python代码正在接收一个表示hdf5文件字节的字节数组。

我想将这个字节数组读取到内存中的h5py文件对象,而无需先将字节数组写入磁盘。 这个页面说我可以打开一个内存映射文件,但它会是一个新的空文件。 我想从字节数组转到内存中的hdf5文件,使用它,放弃它,不要在任何时候写入磁盘。

是否可以用h5py来做到这一点? (或使用C的hdf5,如果这是唯一的方法)

My python code is receiving a byte array which represents the bytes of the hdf5 file.

I'd like to read this byte array to an in-memory h5py file object without first writing the byte array to disk. This page says that I can open a memory mapped file, but it would be a new, empty file. I want to go from byte array to in-memory hdf5 file, use it, discard it and not to write to disk at any point.

Is it possible to do this with h5py? (or with hdf5 using C if that is the only way)

最满意答案

您可以尝试使用Binary I / O创建一个File对象并通过h5py读取它:

f = io.BytesIO(YOUR_H5PY_STREAM) h = h5py.File(f,'r')

You could try to use Binary I/O to create a File object and read it via h5py:

f = io.BytesIO(YOUR_H5PY_STREAM) h = h5py.File(f,'r')

更多推荐

本文发布于:2023-04-21 18:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/3f9228164eeb3535465bd0700f3c3f93.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   字节   加载   内存   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!