0

I can create tar files compressed using LZMA as such:

$ ls ./DbDumps
alpha.dmp
beta.dmp
delta.dmp
$ XZ_OPT=-9 tar cJf dbDumps.tar.xz DbDumps

But, what I really want to do (but cannot) is compress each individual file, and then create the tar file.  For example:

$ cd DbDumps
$ xz.exe *dmp
$ cd ..
$ tar cf dbDumps.tar DbDumps

Should I investigate HomeBrew? XZ.pkg?

Actually, back in October www.aeyoun.com claimed that Yosemite, other than via tar, does not support *.xz file compression. Is this correct? Might it be that "*xz" is doable, but Apple just won't say "it is officially supported"?

3
  • Are you saying that you cannot do it because xz is not installed? I would imagine that xz must surely be installed, because you are able to get tar to use it. Commented Jul 4, 2015 at 3:29
  • @Celada No. the "xz" executable is not in my $PATH. I could look around the file system for the executable. But,, can you recommend a place for me to get the executable and install it? Is "homebrew"or"XZ.pkg" where I should start? Commented Jul 4, 2015 at 3:42
  • Homebrew definitely works. That (or maybe Macports) is how I have xz installed on my ancient MacOS 10.5 system, where Apple doesn't provide it. But you shouldn't need to use Homebrew. xz may not be in your $PATH, but it's got to be in there somewhere since tar is successfully using it. The heavy-handed way of finding it would be find / -name xz -print. Commented Jul 4, 2015 at 4:04

2 Answers 2

1

Of course you can. Firstly tar in most cases does not include compression, it hands that off to a helper (if it supports it at all). At first that helper was compress (.tar.Z). I have also seen gzip (.tar.gz or .tgz), bzip2 (.tar.bz2), infozip's zip and unzip tools (.tar.zip), and some I cant rember the official names for (.tar.lha, .tar.lhz, .tar.zoo, tar.bz, tar.z). All of these use compression separate from tar. so the easy way to do it would be just to find the path to the xz binary (it would be called xz not xz.exe). If it is not already installed on the system, the easiest way would be to install it from a third party repository like macports. And if all else fails you can always install from source (although I cannot imagine that it would come to this).

1
  • awesome. I can take thinks from here. thanks very much. Commented Jul 4, 2015 at 3:48
0

If you are looking for "per file" compression, within an archive, you could use .zip as your container format. Whilst the zip format is most commonly used with Deflate (the same compression method used by zlib and gzip), it does support several other methods, such as Deflate64, BZip2, PPMd and LZMA. All of these (and more) are part of the ZIP APPNOTE published by PKWare (the company founded by Phil Katz, the inventor of the zip standard).

LZMA is interesting as it is basically the same compression method as that found in XZ (Ok, technically these days XZ defaults to LZMA2 but the advantages of version 2 are not compression size or speed related).

Now, Apple being Apple they don't include anything other than the Deflate method in their standard zipping tools like Archive Utility and ditto (even though LZMA has been part of the specification since 2006). In fact they even hobbled their bundled Infozip tools, so that they too only have Deflate (even though these same tools do support better methods on other platforms).

However, recent macOS includes Python 3.8.2 with the zipfile, bz2 & lzma modules, so you can open a zip with bzip2 or lzma methods on macOS out of the box.

If knocking up a little Python script is beyond you, there are easier ways. Python provides a command line interface to manipulate zips. That interface defaults to compressing with Deflate but a very minor hack will change this default:

echo '#!/usr/bin/python3' |\
cat - /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/Current/lib/python*/zipfile.py |\
sed '/zf\.write/s/DEFLATED/LZMA/' > ziplzma
chmod +x ziplzma

You can now use the script and with its normal options but it will default to LZMA for compression.

./ziplzma -c dbDumps.zip DbDumps

Run ./ziplzma -h for more options.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.