简体   繁体   English

使用 CURL 或 WGET 读取 Gzip 文件页脚

[英]Reading Gzip File Footer with CURL or WGET

I have a gzip file in the web server.我在 Web 服务器中有一个 gzip 文件。 I want to download the file only if there is enough disk space to decompress the file.我只想在有足够的磁盘空间来解压缩文件时下载文件。 Is it possible to know the decompress size before downloading the file?在下载文件之前是否可以知道解压大小?

The decompressed size is encoded in the footer of the gzip file [1] .解压后的大小编码在 gzip 文件[1]的页脚中。 We can extract the decompressed size with the following command我们可以使用以下命令提取解压后的大小

gzip -l gzip -l

But, the file need to be downloaded.但是,需要下载文件。 I want to avoid the file downloading if I could know the decompressed size.如果我知道解压缩的大小,我想避免下载文件。

You can hack your way with the HTTP Range header , but it will take many http requests and your server needs to accept the Range header.您可以使用HTTP Range header来破解自己的方式,但这需要很多 http 请求,并且您的服务器需要接受Range标头。

  1. Send a first request with the HEAD method, to figure out the total file size content-length使用HEAD方法发送第一个请求,计算总文件大小content-length
  2. Send a second request with a Range header to get the last 4 bytes of the file.发送带有Range标头的第二个请求以获取文件的最后 4 个字节。 Compute theses bytes to know the file size计算这些字节以了解文件大小
  3. If you have enough size available on the disk (file-size + uncompressed size), download the full file.如果磁盘上有足够的可用大小(文件大小 + 未压缩大小),请下载完整文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM