如何使用 7z DLL 压缩许多小数据块并将其附加到文件中
我想使用 7z DLL 将少量数据附加到一个压缩文件中。目前我最好的猜测是解压缩 7z 文件,附加数据,然后重新压缩它。显然,如果 7z 文件的大小变大(例如 1 GB)并且我想每秒保存一个新块,那么这不是一个性能良好的解决方案。我怎样才能以更好的方式做到这一点?
我可以使用 7z DLL 支持的任何压缩格式。
I would like to use the 7z DLL to append small amounts of data to one compressed file. At the moment my best guess would be uncompress the 7z file, append the data, and recompress it. Obviously, this is not a good solution performance wise, if the size of the 7z file becomes large (say 1 gb) and I want do save a new chunk every second. How could I do this in a better way?
I could use any compression format supported by the 7z DLL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看一下 Python LZMA 绑定(LZMA 是 7z 的压缩算法名称) ,你应该做你想做的事情,而不需要 ctypes 的东西。
编辑
待确认,但快速查看py7zlib。 py 显示仅支持读取 7z 文件,不支持写入。然而,在 src 目录中有一个
pylzma_compressfile.c
,所以也许有一些事情要做。编辑2
pylzma.compressfile 函数似乎在那里,很好。
Have a look at the Python LZMA bindings (LZMA is the compression algorithm name of 7z), you should do what you want without ctypes stuff.
EDIT
To be confirmed, but a quick look at py7zlib.py shows only support for reading 7z files, not writing. However in the src dir there's a
pylzma_compressfile.c
, so maybe there's something to do.EDIT 2
The pylzma.compressfile function seems to be there, so fine.
这不是我的答案。
如何使用 Python 中的 DLL 文件?
我想ctypes 是正确的选择。
以下 ctypes 示例来自我编写的实际代码(在 Python 2.5 中)。到目前为止,这是我发现执行您要求的操作的最简单方法。
ctypes 包含所有 C 类型数据类型(int、char、short、void*、...),并且可以按值或引用传递。它还可以返回特定的数据类型,尽管我的示例没有这样做(HLL API 通过修改按引用传递的变量来返回值)。
This is NOT MY ANSWER.
How can I use a DLL file from Python?
I think ctypes is the way to go.
The following example of ctypes is from actual code I've written (in Python 2.5). This has been, by far, the easiest way I've found for doing what you ask.
The ctypes stuff has all the C-type data types (int, char, short, void*, ...) and can pass by value or reference. It can also return specific data types although my example doesn't do that (the HLL API returns values by modifying a variable passed by reference).