7zip如何单个文件压缩_为什么Zip能够比具有相同内容的多个文件更好地压缩单个文件?...

7zip如何单个文件压缩

7zip如何单个文件压缩

zip-compresses-single-files-better-than-multiple-files-with-same-content-00

Being able to compress our files so that it is easier to share and/or transport them can make our electronic lives much easier, but sometimes we may see odd or unexpected sizing results after we compress them. Why is that? Today’s SuperUser Q&A post has the answers to a confused reader’s questions.

能够压缩文件以便更轻松地共享和/或传输它们可以使我们的电子生活变得更加轻松,但是有时我们在压缩文件后可能会看到奇怪或意外的大小调整结果。 这是为什么? 今天的“超级用户问答”帖子解答了一个困惑的读者的问题。

Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.

今天的“问答”环节由SuperUser提供,它是Stack Exchange的一个分支,该社区是由社区驱动的Q&A网站分组。

Photo courtesy of Jean-Etienne Minh-Duy Poirrier (Flickr).

照片由Jean-Etienne Minh-Duy Poirrier(Flickr)提供

问题 (The Question)

SuperUser reader sixtyfootersdude wants to know why zip is able to compress single files better than multiple files with the same type of content:

超级用户阅读器sixtyfootersdude想知道为什么zip能够比具有相同内容类型的多个文件更好地压缩单个文件:

Suppose that I have 10,000 XML files and want to send them to a friend. Before sending them, I would like to compress them.

假设我有10,000个XML文件,并想将它们发送给朋友。 在发送它们之前,我想对其进行压缩。

Method 1: Do Not Compress Them

方法1:不要压缩它们

Results:

结果:

zip-compresses-single-files-better-than-multiple-files-with-same-content-01

Method 2: Zip Every File Separately and Send Him 10,000 Zipped XML Files

方法2:分别压缩每个文件并向他发送10,000个压缩的XML文件

Command:

命令:

zip-compresses-single-files-better-than-multiple-files-with-same-content-02

Results:

结果:

zip-compresses-single-files-better-than-multiple-files-with-same-content-03

Method 3: Create a Single Zip File Containing All 10,000 XML Files

方法3:创建一个包含所有10,000个XML文件的单个Zip文件

Command:

命令:

zip-compresses-single-files-better-than-multiple-files-with-same-content-04

Results:

结果:

zip-compresses-single-files-better-than-multiple-files-with-same-content-05

Method 4: Concatenate the Files Into a Single File and Zip It

方法4:将文件串联成单个文件并压缩

Command:

命令:

zip-compresses-single-files-better-than-multiple-files-with-same-content-06

Results:

结果:

zip-compresses-single-files-better-than-multiple-files-with-same-content-07

Questions

问题

  • Why do I get such dramatically better results when I am just zipping a single file?

    当我仅压缩单个文件时,为什么会得到如此显着更好的结果?
  • I was expecting to get drastically better results using method 3 rather than method 2, but I do not. Why is this?

    我期望使用方法3而不是方法2能够获得更好的结果,但我没有。 为什么是这样?
  • Is this behaviour specific to zip? If I tried using Gzip, would I get different results?

    这是特定于zip的行为吗? 如果尝试使用Gzip,会得到不同的结果吗?

Additional Info

附加信息

zip-compresses-single-files-better-than-multiple-files-with-same-content-08

Meta Data

元数据

One of the answers given suggests that the difference is the system meta data that is stored in the zip file. I do not believe that this can be the case. To test it, I did the following:

给出的答案之一表明区别在于存储在zip文件中的系统元数据。 我认为情况并非如此。 为了测试它,我做了以下工作:

zip-compresses-single-files-better-than-multiple-files-with-same-content-09

The resulting zip file is 1.4 MB. This means that there is still approximately ten MB of unexplained space.

最终的zip文件为1.4 MB。 这意味着仍有大约十MB的无法解释的空间。

Why is zip able to compress single files better than multiple files with the same type of content?

为什么zip能够比具有相同内容类型的多个文件更好地压缩单个文件?

答案 (The Answer)

SuperUser contributors Alan Shutko and Aganju have the answer for us. First up, Alan Shutko:

超级用户贡献者Alan Shutko和Aganju为我们提供了答案。 首先,Alan Shutko:

Zip compression is based on repetitive patterns in the data to be compressed, and the compression gets better the longer the file is, as more and longer patterns can be found and used.

Zip压缩基于要压缩的数据中的重复模式,文件越长,压缩越好,因为可以找到并使用越来越多的模式。

Simplified, if you compress one file, the dictionary that maps (short) codes to (longer) patterns is necessarily contained in each resulting zip file; if you zip one long file, the dictionary is ‘reused’ and grows even more effective across all content.

简化后,如果压缩一个文件,则在每个结果zip文件中都必须包含将(短)代码映射为(长)模式的字典。 如果您压缩一个长文件,字典将被“重用”,并且在所有内容上都将变得更加有效。

If your files are even a bit similar (as text always is), reuse of the ‘dictionary’ becomes very efficient and the result is a much smaller total zip file.

如果您的文件甚至有点相似(就像文本一样),则“字典”的重用变得非常有效,结果是总的zip文件要小得多。

Followed by the answer from Aganju:

随后是Aganju的回答:

In zip, each file is compressed separately. The opposite is solid compression, that is, files are compressed together. 7-zip and Rar use solid compression by default. Gzip and Bzip2 cannot compress multiple files, so Tar is used first, having the same effect as solid compression.

在zip中,每个文件分别压缩。 相反是实体压缩,即文件压缩在一起。 默认情况下,7-zip和Rar使用实体压缩。 Gzip和Bzip2无法压缩多个文件,因此首先使用Tar,其效果与实体压缩相同。

As xml files have similar structure (and probably similar content), if the files are compressed together then the compression will be higher.

由于xml文件具有相似的结构(并且可能具有相似的内容),因此,如果将文件压缩在一起,则压缩率会更高。

For example, if a file contains the string “<content><element name=” and the compressor has already found that string in another file, it will replace it with a small pointer to the previous match. If the compressor does not use solid compression, the first occurrence of the string in the file will be recorded as a literal, which is larger.

例如,如果一个文件包含字符串“ <content> <element name = ”,并且压缩程序已经在另一个文件中找到该字符串,它将用一个指向先前匹配项的小指针替换它。 如果压缩程序不使用整体压缩,则字符串在文件中的首次出现将记录为文字,该文字更大。



Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.

有什么补充说明吗? 在评论中听起来不错。 是否想从其他精通Stack Exchange的用户那里获得更多答案? 在此处查看完整的讨论线程

翻译自: https://www.howtogeek.com/237543/why-is-zip-able-to-compress-single-files-better-than-multiple-files-with-the-same-content/

7zip如何单个文件压缩

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值