為什麼zip壓縮單個檔案比壓縮具有相同內容的多個檔案更好?

能夠壓縮我們的檔案以便更容易地共享和/或傳輸它們可以使我們的電子生活更容易,但有時我們在壓縮檔案後可能會看到奇怪或意外的大小調整結果。為什麼?今天的超級使用者問答帖子回答了一位困惑讀者的問題。...

為什麼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:

007Ys3FFgy1gpe1313sv9j30hd01lt8k

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

Command:

007Ys3FFgy1gpe131pnypj30hd010dfn

Results:

007Ys3FFgy1gpe1328on6j30hd01lt8k

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

Command:

007Ys3FFgy1gpe132tcjkj30hd00yjr9

Results:

007Ys3FFgy1gpe133d6t3j30hd01lq2s

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

007Ys3FFgy1gpe134a8taj30hd09iaay

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
  • 閱讀 ( 49 )
  • 分類:網際網路

你可能感興趣的文章

適用於執行ios 11的iPad的最佳拖放應用程式

... 你最喜歡的iPad生產力應用程式是什麼?他們支援拖放嗎?在下面的評論中與我們分享。 ...

  • 發佈於 2021-03-11 18:40
  • 閲讀 ( 53 )

壓縮的html是如何工作的以及為什麼需要它

... 在本文中,我們將討論縮小HTML檔案的兩種主要方法,為什麼要縮小HTML檔案,以及如何縮小。 ...

  • 發佈於 2021-03-14 09:00
  • 閲讀 ( 47 )

如何在windows10中節省磁碟空間

...空間方面,您還使用了哪些技巧和技巧?如果我們錯過了什麼,或者你還有其他想法,我們很樂意聽到你的訊息。請在下面發表評論! ...

  • 發佈於 2021-03-14 10:03
  • 閲讀 ( 49 )

如何在mac上開啟和提取rar檔案

... 在這個快速概述中,您將瞭解有關RAR檔案是什麼、存在的原因以及如何在Mac上開啟和提取RAR檔案內容的所有資訊。 ...

  • 發佈於 2021-03-25 09:15
  • 閲讀 ( 48 )

在Windows10上建立zip檔案的6種簡單方法

... 不管出於什麼原因,在Windows上建立ZIP檔案都有內建和第三方選項。以下是在Windows10上建立ZIP檔案的六種方法。 ...

  • 發佈於 2021-03-28 11:34
  • 閲讀 ( 39 )

想保持個人資料的安全嗎?下面是如何加密檔案

... 為什麼需要檔案加密? ...

  • 發佈於 2021-03-28 13:03
  • 閲讀 ( 43 )

谷歌應用程式對這些檔案的8個奇妙用途

... 7解壓縮zip檔案 ...

  • 發佈於 2021-03-28 15:36
  • 閲讀 ( 60 )

如何在mac上製作zip檔案

... 本指南將介紹什麼是ZIP檔案,以及如何在macOS中建立ZIP檔案。 ...

  • 發佈於 2021-03-28 16:40
  • 閲讀 ( 67 )

如何使用powershell壓縮(和解壓)檔案

ZIP檔案格式透過將檔案壓縮為單個檔案來減小檔案的大小。這個過程節省了磁碟空間,加密了資料,並使與其他人共享檔案變得容易。下面介紹如何使用PowerShell壓縮和解壓檔案。 如何使用powershell壓縮檔案 讓我們首先使用Compr...

  • 發佈於 2021-04-02 01:39
  • 閲讀 ( 47 )

如何在mac上壓縮和解壓檔案和資料夾

Macs附帶了一個強大的內建壓縮工具,可以幫助您壓縮和解壓檔案和資料夾。另外,它很容易使用!為了增加功能,您也可以嘗試使用第三方應用程式。 首先,讓我們討論一下內建的歸檔實用工具。它不是一個應用程式,而是一...

  • 發佈於 2021-04-02 03:45
  • 閲讀 ( 42 )
魔法仙女小畜生
魔法仙女小畜生

0 篇文章

作家榜

  1. admin 0 文章
  2. 孫小欽 0 文章
  3. JVhby0 0 文章
  4. fvpvzrr 0 文章
  5. 0sus8kksc 0 文章
  6. zsfn1903 0 文章
  7. w91395898 0 文章
  8. SuperQueen123 0 文章

相關推薦