能夠壓縮我們的檔案以便更容易地共享和/或傳輸它們可以使我們的電子生活更容易,但有時我們在壓縮檔案後可能會看到奇怪或意外的大小調整結果。為什麼?今天的超級使用者問答帖子回答了一位困惑讀者的問題。
今天的問答環節是由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:
Method 2: Zip Every File Separately and Send Him 10,000 Zipped XML Files
Command:
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***
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:
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使用者那裡瞭解更多答案嗎?在這裡檢視完整的討論主題。
... 你最喜歡的iPad生產力應用程式是什麼?他們支援拖放嗎?在下面的評論中與我們分享。 ...
... 在本文中,我們將討論縮小HTML檔案的兩種主要方法,為什麼要縮小HTML檔案,以及如何縮小。 ...
...空間方面,您還使用了哪些技巧和技巧?如果我們錯過了什麼,或者你還有其他想法,我們很樂意聽到你的訊息。請在下面發表評論! ...
... 在這個快速概述中,您將瞭解有關RAR檔案是什麼、存在的原因以及如何在Mac上開啟和提取RAR檔案內容的所有資訊。 ...
... 不管出於什麼原因,在Windows上建立ZIP檔案都有內建和第三方選項。以下是在Windows10上建立ZIP檔案的六種方法。 ...
ZIP檔案格式透過將檔案壓縮為單個檔案來減小檔案的大小。這個過程節省了磁碟空間,加密了資料,並使與其他人共享檔案變得容易。下面介紹如何使用PowerShell壓縮和解壓檔案。 如何使用powershell壓縮檔案 讓我們首先使用Compr...
Macs附帶了一個強大的內建壓縮工具,可以幫助您壓縮和解壓檔案和資料夾。另外,它很容易使用!為了增加功能,您也可以嘗試使用第三方應用程式。 首先,讓我們討論一下內建的歸檔實用工具。它不是一個應用程式,而是一...