下载时解压压缩包
我有一个程序可以下载通过互联网分割的 rar 文件的第 01 部分,然后是第 02 部分等。 我的程序首先下载part01,然后下载part02,依此类推。 经过一些测试,我发现使用例如 UnRAR2 for python,我可以提取存档中包含的文件的第一部分(.avi 文件),并且我可以在前几分钟播放它。当我添加另一个文件时,它会提取更多内容,依此类推。我想知道的是:是否可以在下载单个文件时提取它们? 我需要它开始提取part01,而不必等待它完成下载......这可能吗?
非常感谢!
马泰奥
I've got a program that downloads part01, then part02 etc of a rar file split across the internet.
My program downloads part01 first, then part02 and so on.
After some tests, I found out that using, on example, UnRAR2 for python I can extract the first part of the file (an .avi file) contained in the archive and I'm able to play it for the first minutes. When I add another file it extracts a bit more and so on. What I wonder is: is it possible to make it extract single files WHILE downloading them?
I'd need it to start extracting part01 without having to wait for it to finish downloading... is that possible?
Thank you very much!
Matteo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在谈论 rar 档案中的 .avi 文件。您确定档案确实被压缩了吗? warez 场景发布的视频文件不使用压缩:
(我正在考虑 VLC、BSPlayer、KMPlayer、Dziobas Rar Player、rarfilesource、rarfs,...)
您可以按如下方式检查压缩情况:
如果要提取的版本指示2.0,则存档不使用压缩。 (除非您有十年前的 rars)您可以看到总大小和打包大小将相等。
是。当不使用压缩时,您可以编写自己的程序来提取文件。 (我知道有人编写了一个脚本来直接从外部 rar 文件下载电影;但它不是公开的,我也没有。)因为你提到了 Python,所以我建议你看一下 rarfile 2.2 由 Marko Kreen 编写,如 pyarrfs 做到了。存档只是添加了标头(rar 块)的切碎文件。这将是一个复制操作,您需要暂停直到下载下一个存档。
我坚信压缩文件也是可能的。您此处的方法会有所不同,因为您必须使用 unrar 来提取压缩文件。我必须补充一点,还有一个免费的 RARv3 实现 提取 The Unarchiver 中实现的 rars。
我认为 (un)rar 的这个参数将使之成为可能:
它将使您可以暂停提取,直到下载下一个存档。
当solid选项用于rars时,所有打包文件都被视为一个大文件流。如果您始终从第一个文件开始,即使它不包含您要提取的文件,这也不会导致任何问题。
我还认为它可以与密码档案一起使用。
You are talking about an .avi file inside the rar archives. Are you sure the archives are actually compressed? Video files released by the warez scene do not use compression:
(I'm thinking VLC, BSPlayer, KMPlayer, Dziobas Rar Player, rarfilesource, rarfs,...)
You can check for the compression as follows:
If Version to extract indicates 2.0, then the archive uses no compression. (unless you have decade old rars) You can see Total size and Packed size will be equal.
Yes. When no compression is used, you can write your own program to extract the files. (I know of someone who wrote a script to directly download the movie from external rar files; but it's not public and I don't have it.) Because you mentioned Python I suggest you take a look at rarfile 2.2 by Marko Kreen like the author of pyarrfs did. The archive is just the file chopped up with headers (rar blocks) added. It will be a copy operation that you need to pause until the next archive is downloaded.
I strongly believe it is also possible for compressed files. Your approach here will be different because you must use unrar to extract the compressed files. I have to add that there is also a free RARv3 implementation to extract rars implemented in The Unarchiver.
I think this parameter for (un)rar will make it possible:
It will give you the possibility to pause the extraction until the next archive is downloaded.
When the solid option is used for rars, all packed files are treated as one big file stream. This should not cause any problems if you always start from the first file even if it doesn't contain the file you want to extract.
I also think it will work with passworded archives.
我非常怀疑。根据压缩的本质(根据我的理解),需要每一比特来解压缩它。看来您下载的来源在压缩之前故意将 avi 分成几部分,但是当您应用压缩时,您压缩的任何内容现在都是一个原子单元。所以他们好心地将整个 avi 分成多个部分,但每个部分仍然是一个原子尼特。
但我不是压缩方面的专家。
我目前能想到的唯一测试是这样的:
curl http://example.com/Part01 |解压
。I highly doubt it. By nature of compression (from my understanding), every bit is needed to uncompress it. It seems that the source of where you are downloading from has intentionally broken the avi into pieces before compression, but by the time you apply compression, whatever you compressed is now one atomic unit. So they kindly broke the whole avi into Parts, but each Part is still an atomic nit.
But I'm not an expert in compression.
The only test I can currently think of is something like:
curl http://example.com/Part01 | unrar
.我不知道这是否是针对特定语言提出的,但可以直接从互联网传输压缩的 RAR 并即时解压缩。我可以使用我的 C# 库 http://sharpcompress.codeplex.com/
RAR 格式实际上很友好不错的。它在每个条目之前都有标头,并且压缩数据本身不需要对字节流进行随机访问。
执行多部分文件,您必须首先完全提取第 1 部分,然后在第 2 部分可用时继续写入。
所有这一切都可以通过我的 RarReader API 实现。固体存档也是可流式传输的(事实上,它们只是可流式传输的。您不能随机访问固体存档中的文件。您几乎必须一次将它们全部提取出来。)
I don't know if this was asked with a specific language in mind, but it is possible to stream a compressed RAR directly from the internet and have it decompressed on the fly. I can do this with my C# library http://sharpcompress.codeplex.com/
The RAR format is actually kind of nice. It has headers preceding each entry and the compressed data itself does not require random access on the stream of bytes.
Do it multi-part files, you'd have to fully extract part 1 first, then continue writing when part 2 is available.
All of this is possible with my RarReader API. Solid archive are also streamable (in fact, they're only streamable. You can't randomly access files in a solid archive. You pretty much have to extract them all at once.)