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

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

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

今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的问答网站分组。

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

问题

超级用户读者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.

Method 1: Do Not Compress Them

Results:

007Ys3FFgy1gpe1300zyxj30hd01jglh

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

Command:

007Ys3FFgy1gpe130jxqhj30hd010wec

Results:

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

Command:

Results:

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

Command:

Results:

Questi***

  • 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?
  • Is this behaviour specific to zip? If I tried using Gzip, would I get different results?

Additional Info

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:

007Ys3FFgy1gpe134twd8j30hd01ldfp

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

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

答案

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

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.

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.

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 **aller total zip file.

接下来是阿甘朱的回答:

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.

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

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 **all 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.


有什么要补充的解释吗?在评论中发出声音。想从其他精通技术的Stack Exchange用户那里了解更多答案吗?在这里查看完整的讨论主题。

  • 发表于 2021-04-10 01:56
  • 阅读 ( 221 )
  • 分类:互联网

你可能感兴趣的文章

如何在mac上打开和提取rar文件

...件。两者都是“归档”文件格式,用于将多个单独的文件压缩为单个文件。这样,你只需要把一个文件下载(或附加一个文件到电子邮件),收件人只需要下载一个文件,而不是许多单独的文件。 ...

  • 发布于 2021-03-25 09:15
  • 阅读 ( 284 )

在Windows10上创建zip文件的6种简单方法

...。也许您想将多个文件合并到一个存档中?或者你想通过压缩压缩压缩文件来减小文件的大小? ...

  • 发布于 2021-03-28 11:34
  • 阅读 ( 338 )

如何在mac上制作zip文件

... 什么是压缩文件(a zip file)? ...

  • 发布于 2021-03-28 16:40
  • 阅读 ( 335 )

如何压缩视频并减小文件大小

...的大多数视频都是这样。幸运的是,您可以使用多种方法压缩视频并减小其文件大小。 ...

  • 发布于 2021-03-29 20:56
  • 阅读 ( 420 )

如何使用powershell压缩(和解压)文件

ZIP文件格式通过将文件压缩为单个文件来减小文件的大小。这个过程节省了磁盘空间,加密了数据,并使与其他人共享文件变得容易。下面介绍如何使用PowerShell压缩和解压文件。 如何使用powershell压缩文件 让我们首先使用Compr...

  • 发布于 2021-04-02 01:39
  • 阅读 ( 227 )

如何在mac上压缩和解压文件和文件夹

Macs附带了一个强大的内置压缩工具,可以帮助您压缩和解压文件和文件夹。另外,它很容易使用!为了增加功能,您也可以尝试使用第三方应用程序。 首先,让我们讨论一下内置的归档实用工具。它不是一个应用程序,而是一...

  • 发布于 2021-04-02 03:45
  • 阅读 ( 179 )

如何在Windows10上压缩(和解压)文件

ZIP文件格式通过压缩文件、节省磁盘空间和减少网络传输时间来减小文件的大小。它还允许您将多个文件合并成一个易于与其他人共享的文件。下面是如何在Windows10上压缩和解压文件。 如何创建zip文件(压缩文件夹) 首先,...

  • 发布于 2021-04-02 06:33
  • 阅读 ( 178 )

什么是7z文件(如何打开文件)?

...但实际上更像一个包,让人们将多个文件和文件夹打包并压缩到一个更小的文件中。7Z文件的工作方式相同,并且是流行的7-Zip压缩工具所特有的。 什么是7z文件(a 7z file)? 7Z是用于使用7-Zip(一种免费的开源文件压缩工具)创建...

  • 发布于 2021-04-05 06:06
  • 阅读 ( 203 )

适用于windows的最佳文件归档程序

需要解压缩或压缩一些文件吗?避免像WinZip和WinRAR这样的大牌程序,因为它们充斥着唠叨和广告。现代版本的Windows集成了对ZIP文件的支持,其他任何东西都最好使用免费的开源7-ZIP进行管理。 对于基本的zip文件:windows处理一...

  • 发布于 2021-04-08 21:42
  • 阅读 ( 158 )

linux下如何使用tar命令压缩和提取文件

...后在一个命令中使用gzip或bzip2压缩对其进行压缩。这就是为什么生成的文件是一个。焦油.gz文件或。焦油bz2文件。 压缩整个目录或单个文件 在Linux上,使用以下命令压缩整个目录或单个文件。它还将压缩指定目录中的每个其他...

  • 发布于 2021-04-09 18:42
  • 阅读 ( 159 )
魔法仙女小畜生
魔法仙女小畜生

0 篇文章

相关推荐