This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(6)
诀窍是做Sergio 建议,无需手动执行。如果您通过 HTTP 支持的虚拟文件系统挂载 ZIP 文件,然后使用标准的解压缩命令,这很容易。这样,unzip 实用程序的 I/O 调用就会转换为 HTTP 范围 GET,这意味着只有您希望通过网络传输的 ZIP 文件块。
下面是一个使用 HTTPFS 的 Linux 示例,这是一个非常轻量级的虚拟文件系统(它使用 FUSE)。 Windows 上也有类似的工具。
获取/构建httpfs:
安装远程ZIP文件并从中提取一个文件:
当然,除了命令行工具之外,您还可以使用任何其他工具(我需要< a href="https://en.wikipedia.org/wiki/Sudo" rel="nofollow noreferrer">sudo 因为看起来 FUSE 在我的机器上就是这样设置的,你不需要它)。
The trick is to do what Sergio suggests without doing it manually. This is easy if you mount the ZIP file via an HTTP-backed virtual filesystem and then use the standard unzip command on it. This way the unzip utility's I/O calls are translated to HTTP range GETs, which means only the chunks of the ZIP file that you want get transferred over the network.
Here's an example for Linux using HTTPFS, a very lightweight virtual filesystem (it uses FUSE). There are similar tools for Windows.
Get/build httpfs:
Mount a remote ZIP file and extract one file from it:
Of course you can also use whatever other tools beside the command-line one (I need sudo because it seems FUSE is set up that way on my machine, you shouldn't have to need it).
在某种程度上,是的,你可以。
ZIP 文件格式 表示有一个“中央目录”。基本上,这是一个存储存档中的文件及其偏移量的表。
因此,使用 Content-Range 您可以从下载部分文件最后(中心目录是 ZIP 文件中的最后一个目录)并尝试识别其中的中心目录。如果成功,那么您就知道文件列表和偏移量,因此您可以继续单独获取这些块并自行解压缩。
这种方法很容易出错,并且不能保证有效。但一般来说,黑客攻击也是如此:-)
另一种可能的方法是为此构建一个自定义服务器(请参阅 pst 的答案更多细节)。
In a way, yes, you can.
ZIP file format says that there's a "central directory". Basically, this is a table that stores what files are in the archive and what offsets do they have.
So, using Content-Range you could download part of the file from the end (the central directory is the last thing in a ZIP file) and try to identify the central directory in it. If you succeed then you know the file list and offsets, so you can proceed and get those chunks separately and decompress them yourself.
This approach is quite error-prone and is not guaranteed to work. But so is hacking in general :-)
Another possible approach would be to build a custom server for that (see pst's answer for more details).
普通人可以通过多种方式从压缩的 ZIP 文件中下载单个文件,但不幸的是,这些方式并不是常识。有一些开源工具和在线 Web 服务,包括:
There are several ways for a normal person to be able to download an individual file from a compressed ZIP file, unfortunately they aren't common knowledge. There are some open-source tools and online web services, including:
您可以安排您的文件出现在 ZIP 文件的后面。
下载 100k:
检查我们获得了哪些文件:
然后提取最后一个文件:
You can arrange for your file to appear in the back of the ZIP file.
Download 100k:
Check what files we did get:
Then extract the last file:
我认为Sergio Tulentsev 的想法非常棒。
然而,如果可以控制服务器——例如,可以部署自定义代码——那么映射/处理请求、提取 ZIP 存档的相关部分就是一个相当简单的操作(在事物方案中:) ,并将数据发送回 HTTP 流。
该请求可能如下所示:
这意味着从“myfile.zip”中提取并返回“a.jpeg”。
(我故意选择这种愚蠢的格式,以便浏览器在下载对话框出现时可能会选择“myfile.zip_a.jpeg”作为名称。)
当然,如何实现这一点取决于服务器/language/framework 并且可能已经存在支持类似操作的解决方案(但我不知道)。
I think Sergio Tulentsev's idea is brilliant.
However, if there is control over the server -- e.g., custom code can be deployed -- then it is a rather trivial operation (in the scheme of things :) to map/handle a request, extract the relevant portion of the ZIP archive, and send the data back in the HTTP stream.
The request might look like:
Which would mean extract -- and return -- "a.jpeg" from "myfile.zip".
(I intentionally chose this silly format so that browsers would likely choose "myfile.zip_a.jpeg" as the name in the download dialog when it appears.)
Of course, how this is implemented depends on the server/language/framework and there may already be existing solutions that support a similar operation (but I know not).
基于良好的输入,我在 Powershell 中编写了一个代码片段来展示它是如何工作的:
Based on the good input I have written a code-snippet in Powershell to show how it could work: