r/programming • • Mar 12 '21

7-Zip developer releases the first official Linux version

https://www.bleepingcomputer.com/news/software/7-zip-developer-releases-the-first-official-linux-version/
5.0k Upvotes

377 comments sorted by

View all comments

Show parent comments

151

u/futlapperl Mar 12 '21 edited Mar 12 '21

gzip appears to use the Deflate algorithm. 7z, by default, uses LZMA2, which according to Wikipedia, is an improved version of Deflate. So based on my limited research, 7z should be better. Haven't got any benchmarks, but I think I'll get around to performing some today.

Edit: Someone's tested various algorithms including the aforementioned ones and uploaded a write-up.

105

u/Chudsaviet Mar 12 '21

There is already pretty standard Unix-style (stream) compressor XZ, which uses the same LZMA2.

49

u/futlapperl Mar 12 '21

.xz doesn't seem to be an archive format, instead only supporting single files, so you have to .tar everything first. This explains the common .tar.xz extension. 7z combines those two steps, but so does every other archiving program. Not sure if there are any notable advantages.

130

u/Kissaki0 Mar 12 '21

A 7z will not retain Linux file permissions.

Combining tar with an additional compression is prevalent on Linux. It's also in line with the Unix philosophy of combining/piping programs together.

Tar has a parameter to do the xz step too on compression, and it's no problem on extraction either. So really it's mostly transparent to the user that it's a two layered file compression.

32

u/futlapperl Mar 12 '21

A 7z will not retain Linux file permissions.

Ah, interesting! That's useful to know.

And yeah, I agree, tar sticks to the Unix philosophy of "Do one thing, but do it well." better than 7z.

17

u/Kissaki0 Mar 12 '21

And yeah, I agree, tar sticks to the Unix philosophy of "Do one thing, but do it well." better than 7z.

It’s kind of ironic though how in the next sentence I said tar can do that with a parameter. ;-)

Manually piping and combining things is not very viable to end users. A parameter on a program is much easier to use. Even if the technical implementation will be separated again, the user interface isn’t. I don’t even know if tar embedded the other compression libs statically or uses shared libs or the other binaries.

40

u/Tm1337 Mar 12 '21

I don't want to shoehorn this in, but it is as relevant as it gets.

https://xkcd.com/1168/

6

u/4lteredBeast Mar 13 '21

Funnily enough, xkcd looks like a bunch of parameters you feed the tar command

24

u/barsoap Mar 12 '21

It took literal ages until GNU came around and made tar's x option auto-detect the presence of compression. Before that you had to additionally specify z or j for gz and bzip2, xz is J I think auto-detect has been available for about as long as that.

Hmm. I just tried it, at some point it must also have stopped to operate on /dev/tape if you don't specify a file.

→ More replies (7)

12

u/dreamer_ Mar 12 '21

Manually piping and combining things is not very viable to end users.

Depending on the end user of course ;)

  • Advanced user or developer might need a separate compressor program. Example: when my CI generates extremely large logs, I can just xz them (without tar) - they will be tiny again, because text files compress nicely, and vim will open them anyway (it will decompress them in-memory, I don't need to do it myself).

  • Normal GUI user on Linux does not need to worry about tar, xz, or piping at all. In Gnome: right click on a directory -> Compress -> select .tar.xz -> click "Create"

2

u/Kissaki0 Mar 12 '21

Convenience parameters for combined functionality or piping is not the same as using other programs though. I was talking about the first.

If you have a use case for using a different program of course you just use that. You do not need a parameter on tar for that.

→ More replies (1)
→ More replies (1)

21

u/spider-mario Mar 12 '21

7-zip lets you choose which files to compress together and with which method. For example, you can have an archive with a bunch of HTML files compressed together with LZMA + a big text file compressed on its own with PPMd + a few PDFs stored without compression. You can then read the TOC without decompressing anything, and if you only need one of the HTML files, you need to decompress the LZMA block that contains them, but you don’t need to care about the PDFs or the PPMd text file. You have flexibility from “each file compressed separately” (.zip) to “everything compressed together” (.tar.whatever), though still at file boundaries I believe.

→ More replies (1)

12

u/Chudsaviet Mar 12 '21

This is exactly what I meant when saying XZ is Unix-style stream compression. In Unix world, its more an advantage I think.

5

u/andynzor Mar 12 '21

The LZMA/XZ archive format was explicitly created to allow using the 7-zip algorithm with *NIX tools (more specifically, to fit more Slackware packages to a CD image). It used the LZMA SDK created by Igor Pavlov himself, with his knowledge and support.

4

u/afiefh Mar 12 '21

I wonder if the inadequacies of the XZ format were ever addressed.

3

u/Chudsaviet Mar 12 '21

Thank, its very interesting under-the-hood article.

3

u/radarsat1 Mar 12 '21

so does every other archiving program

well, all other archiving programs except most archiving programs typically used in Linux. gzip and bzip2 work the same way, on a single file. You can use gzip, bzip2, and xz on a tar in one command using options to "tar".

3

u/[deleted] Mar 12 '21

.xz doesn't seem to be an archive format

It actually is one, but it's not a good archive format.

Not sure if there are any notable advantages.

Random file lookup is one advantage of the combined formats.

4

u/futlapperl Mar 12 '21

I just thought about this. Can you even take a look at the directory structure of the files within a .tar.gz without decompressing the entire thing? Doesn't seem like it would be possible.

6

u/[deleted] Mar 12 '21

nope, tar has no index unlike eg. zip

→ More replies (3)
→ More replies (12)

20

u/eyal0 Mar 12 '21

You can't just compare compression ratioa. You have to look at the time spent on operations.

One algorithm can dominate smith is it's better in at least one measure and no worse in all the other measures.

13

u/futlapperl Mar 12 '21

The article I posted takes time spent into consideration.

6

u/smiler82 Mar 12 '21

You can't just compare compression ratioa. You have to look at the time spent on operations.

Which is why we use http://www.radgametools.com/oodlekraken.htm for compressing our bulk content in games.

→ More replies (3)