Are hard links possible in a zip archive?

I am creating a zip archive containing two identical files on different paths. Does the zip archive format support something similar to the Unix hard link concept? By this I mean the ability to save the file only once (saving a space), but to index this data blog into two different paths in the zip archive.

If the file format supports this, how can I start creating such an archive with the free tools in Ubuntu?

+4
source share
3 answers

No, the Zip file format does not support this. This is because the local file header contains information about the file, including its name, and then immediately compressed data for the file. It is not possible to point two different local file headers to the same compressed data.

+7
source

As @Greg said, ZIP does not support hardlinks.

But if I understand correctly, your goal is to reduce the size of the compressed archive. So think about an alternative solution.

Allows you to run simple tests to check the degree of compression of various archive libraries. I created two identical binaries and compressed them using ZIP, BZ2, RAR and 7z.

8641969 test.bin 8641969 test2.bin 

The first time only one file was compressed. The second time, two files were compressed:

ZIP

 $zip -9 test1.zip test.bin $zip -9 test2.zip test.bin test2.bin 8636837 test1.zip 17273654 test2.zip 

Bzip2

 $export BZIP=--fast $tar cjf test1.tbz test.bin $tar cjf test2.tbz test.bin test2.bin 8694997 test1.tbz 17389167 test2.tbz 

7z

 $7za -mx=9 test1.7z test.bin $7za -mx=9 test2.7z test.bin test2.bin 8705285 test1.7z 8707054 test2.7z 

Rar

 $rar a -m5 test1.rar test.bin $rar a -m5 test2.rar test.bin test2.bin 8649970 test1.rar 17299916 test2.rar 

Conclusion : Only 7z seems to do the job well. Think about how to use it in your application.

Of course, you will need to do more tests in your environment with your files to see if this is really necessary. You can also play with the options to see at what compression level you get the best compression ratio / speed balance.

+7
source

tar archives support hard links

+3
source

Source: https://habr.com/ru/post/1390945/


All Articles