用Python将RAR文件的内容读入内存

用Python将RAR文件的内容读入内存

本文介绍了用Python将RAR文件的内容读入内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种将rar档案中的特定文件读入内存的方法.具体来说,它们是编号图像文件的集合(我正在写漫画阅读器).虽然我可以简单地解压缩这些文件并根据需要加载它们(完成后将其删除),但我还是希望避免这种情况.

I'm looking for a way to read specific files from a rar archive into memory. Specifically they are a collection of numbered image files (I'm writing a comic reader). While I can simply unrar these files and load them as needed (deleting them when done), I'd prefer to avoid that if possible.

总而言之,如果可能的话,我更喜欢跨平台(Windows/Linux)的解决方案,但是Linux是必须的.同样重要的是,如果您要为我指出一个库来处理该问题,请理解该库必须是免费的(例如在啤酒中)或OSS.

That all said, I'd prefer a solution that's cross platform (Windows/Linux) if possible, but Linux is a must. Just as importantly, if you're going to point out a library to handle this for me, please understand that it must be free (as in beer) or OSS.

推荐答案

真正的答案是没有图书馆,而你不能建立图书馆.您可以使用rarfile,也可以使用7zip unRAR(比7zip便宜,但是像啤酒一样免费),但是这两种方法都需要一个外部可执行文件.RAR许可证基本上需要这样做,因为尽管可以获取unRAR的源代码,但是不能以任何方式对其进行修改,并且将其变成库将构成非法修改.

The real answer is that there isn't a library, and you can't make one. You can use rarfile, or you can use 7zip unRAR (which is less free than 7zip, but still free as in beer), but both approaches require an external executable. The license for RAR basically requires this, as while you can get source code for unRAR, you cannot modify it in any way, and turning it into a library would constitute illegal modification.

此外,不能随机访问可靠的RAR归档文件(压缩程度最好的文件),因此无论如何您都必须对整个文件进行归档.WinRAR提供了一个似乎可以避免这种情况的UI,但实际上,它只是在后台解压缩和重新打包存档.

Also, solid RAR archives (the best compressed) can't be randomly accessed, so you have to unarchive the entire thing anyhow. WinRAR presents a UI that seems to avoid this, but really it's just unpacking and repacking the archive in the background.

这篇关于用Python将RAR文件的内容读入内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 00:04