APFS – How to Enable Transparent Compression

apfscompressionfilesystemmacos

How do i enable transparent filesystem compression on any APFS volume?
Or check if it is already enabled?

I am expecting something similiar to NTFS compressed attribute.
According to Wiki it should be supported.

Is it per file or volume ?

I am using Mojave 10.14.0, volumes without encryption.

Best Answer

The standard Mojave setup does have APFS compression implemented, but there's no user visible tools that allows you yourself to select files/folders for compression.

It seems that the "ditto" command supplied with macOS is supposed to be able to employ compression on APFS, but it only actually works with HFS+ file systems.

However, even though no user visible tools comes with Mojave - the developer level APIs are actually there. A third party utility exists that uses these APIs to provide a user tool for compressing files/folders:

https://github.com/RJVB/afsctool

You refer to the wikipedia page for your statement that APFS compression is supported. The wikipedia page actually refers to the above mentioned tool for that support.

You can install afsctool from Homebrew by this command:

brew install afsctool

And you can install afsctool from MacPorts by this command:

sudo port install afsctool

You can compress a file or folder like this:

afsctool -c filename

where filename can be the name of a file or a folder.

You can check if a file is compressed, and how much, by this command:

afsctool -v filename

The built-in compression feature of APFS is implemented in the same way as it was on HFS+. That support was introduced with OS X 10.6. Even though it has thus been a part of the macOS system for almost 10 years, it is not really widely used.

In my own experience it just works (HFS+ or APFS - doesn't matter). However, you might run into an edge case where some program reports the file size incorrectly or something like that. I haven't seen any such misbehavior yet. The whole idea with transparent compression is that user programs do not need to know that compression is used at all.