Å kunne komprimere våre filer slik at det er lettere å dele og / eller transportere dem, kan gjøre våre elektroniske liv lettere, men noen ganger kan vi se merkelige eller uventede størrelsesresultater etter at vi har komprimert dem. Hvorfor det? Dagens SuperUser Q & A innlegg har svar på en forvirret leser spørsmål.
Dagens Spørsmål & Svar-sesjon kommer til oss med høflighet av SuperUser-en underavdeling av Stack Exchange, en fellesskapsdrevet gruppering av Q & A-nettsteder.
Foto courtesy av Jean-Etienne Minh-Duy Poirrier (Flickr).
Spørsmålet
SuperUser leser sixtyfootersdude vil vite hvorfor zip er i stand til å komprimere enkle filer bedre enn flere filer med samme type innhold:
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:
Image
Method 2: Zip Every File Separately and Send Him 10,000 Zipped XML Files
Command:
Results:
Image
Method 3: Create a Single Zip File Containing All 10,000 XML Files
Command:
Results:Image
Method 4: Concatenate the Files Into a Single File and Zip It
Command:
Results:Image
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?
Is this behaviour specific to zip? If I tried using Gzip, would I get different results?
Additional Info
Image
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.
Hvorfor er zip i stand til å komprimere enkle filer bedre enn flere filer med samme type innhold?
Svaret
SuperUser-bidragsytere Alan Shutko og Aganju har svaret for oss. Først opp, 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.
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 smaller total zip file.
Etterfulgt av svaret fra 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.
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 “” 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.
Har du noe å legge til forklaringen? Lyder av i kommentarene. Vil du lese flere svar fra andre tech-savvy Stack Exchange-brukere? Sjekk ut hele diskusjonstråden her.
Noen gang sitte ned for å se på en trailer for det nyeste videospillet, bare for å finne deg ut av stolen og danse med spenning på slutten av det? "Grafikken ser så bra ut, og så du eksplosjonen? Det var som om jeg faktisk var der! "
Hvis du noen gang har brukt begge plattformene - spesielt lytter til lyd gjennom hodetelefoner - har du sannsynligvis lagt merke til at iPhone generelt har bedre lyd og mer volum enn Android. Men hvorfor er det?
Hvis du er ny på prosessen med å konvertere lydfiler, kan mange av detaljene og hvordan de fungerer, være litt forvirrende når du får uventede resultater. Så hva gjør du for å fikse problemet? Dagens SuperUser Q & A innlegg har svaret på en forvirret leser spørsmål.
Hvis du bytter fra iOS til Android og sender eller mottar video meldinger, måtte du sannsynligvis godta en hard virkelighet: Videobilder ser forferdelig ut på Android. La oss ta en titt på hvorfor dette skjer, og måter å bekjempe problemet på.