How to transparently compress a directory

compressionhfs+

I'd like to enable HFS+ compression for a directory, applying it to both the existing files in that directory and newly copied files. I expect to be able to read and write the contents of that directory normally.

Does HFS+ treat non-compressible files intelligently, say by trying to compress the first few KB of the file and bailing if it doesn't compress? I don't want non-compressible files expanding or their access significantly slowed down by compression and de-compression.

Is this possible to do out of the box in Yosemite? I'm also open to installing a third-party app (even a command-line one) to enable the compression, if I can then uninstall it later and have the directory retain the compression.

I found afsctool, but it hasn't had a release or update in an year and a half, and I don't want to use unmaintained software. Besides, afsctool works only for existing files, not newly copied ones.

Best Answer

The compression is supported by HFS+ file-system out of box, however macOS by default doesn't compress any files.


afsctool

There is a afsctool command-line utility which can transparently compress the files, for example:

afsctool -c some_dir

Install via: brew install afsctool.


ditto

When copying files, use ditto, e.g.

ditto --hfsCompression src dst

When copying files or extracting content from an archive, all the content will be compressed if appropriate.

To check whether a file is compressed using HFS+ compression or not, you can use hfsdebug. See: Compress files with HFS+ compression.


Related: Transparent file compression apps for macOS.