Apple Archive .zlib compression algorithm unarchiving

Hello,

I want to archive a folder containing files into a single file using Apple Archive. So far so good, it works as it should.

Now, the documentation says:

The zlib compression algorithm, which is recommended for cross-platform compression.

The encoded format is the raw DEFLATE format as described in IETF RFC 1951, the following obtains the equivalent configuration of the encoder: deflateInit2(zstream,5,Z_DEFLATED,-15,8,Z_DEFAULT_STRATEGY)

Thus, I'm using .zlib, because I want the archive to be unarchivable on macOS as well as other, non-Apple platforms.

The thing is, I don't know what file extension to use so it is unarchivable / openable on both macOS and, say, Windows.

Using .aar ("Apple Archive"), or .aea ("Apple Encrypted Archive"), it works on macOS, but I doubt those can be opened on Windows (since it's the Apple-proprietary file format).

  • Using .zip doesn't work on macOS, so I doubt it'll work on Windows.
  • Using .zlib doesn't work (can't be opened on macOS)
  • Usng .z doesn't work (can't be opened on macOS)

So my question is, with a folder compressed using .zlib for cross-platform, what file extension must I use for the resulting archived file so it can be opened with an unarchiving app on macOS and non-Apple platforms?

Thank you for any insights,

Matthias

Accepted Reply

You are mixing up your terms here:

  • Apple archive is the name of an archive format, much like a tar archive or zip archive.

  • Apple Archive is (confusingly) the name of a framework that implements the Apple archive format.

  • Zlib is a compression format, one that applies to a stream of bytes.

Zlib is a standard stream compression format and support for it shows up in all sorts of places. Apple archive is not a widely adopted archive format and you’ll only find it supported on Apple platforms.

If you want to create an archive to share with other platforms, your best option is to create a zip archive [1]. Unfortunately Apple Archive (the framework) is not able to do this (r. 54528696). Moreover, Apple platforms have no good API for working with zip archives [2]. You will need to write or acquire your own library for this.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Within that zip archive the individual streams may be compressed by zlib but that’s not that salient point here.

[2] If you only want to create archives, and you can live with its otherh limitations, you can use the technique described in this post.

Replies

You are mixing up your terms here:

  • Apple archive is the name of an archive format, much like a tar archive or zip archive.

  • Apple Archive is (confusingly) the name of a framework that implements the Apple archive format.

  • Zlib is a compression format, one that applies to a stream of bytes.

Zlib is a standard stream compression format and support for it shows up in all sorts of places. Apple archive is not a widely adopted archive format and you’ll only find it supported on Apple platforms.

If you want to create an archive to share with other platforms, your best option is to create a zip archive [1]. Unfortunately Apple Archive (the framework) is not able to do this (r. 54528696). Moreover, Apple platforms have no good API for working with zip archives [2]. You will need to write or acquire your own library for this.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Within that zip archive the individual streams may be compressed by zlib but that’s not that salient point here.

[2] If you only want to create archives, and you can live with its otherh limitations, you can use the technique described in this post.

Thank you, eskimo. As always, you've brought clarity into this situation.

I just want to turn a folder of files into a single "binary data" file, so that I can upload it to iCloud and create a shareable link for it, and have it be openable on all sorts of operating systems, so I'll give [2] a shot, perhaps it's enough.

I understand now that using the Apple Archive framework to create an archive of a folder (compressed or not) will only produce "Apple (Encrypted) Archive" files, openable only on Apple platforms. If I need something else, I'd have to go a level deeper and use a (zip) compression based on the Compression framework. I see now that the documentation for AppleArchive.Algorithm.zlib is more or less just a reflection of the Compression framework's equivalent, "COMPRESSION_ZLIB", and does not actually mean that using it will render the file created by the Apple Archive framework openable on other operating systems. That may be true for the Compression framework, but not the Apple Archive framework.

There is a great Swift zip library out there (ZIPFoundation), actually based on the Compression framework, in case anyone needs it: https://github.com/weichsel/ZIPFoundation (I might default to it as well for this, but I like to use as little external libraries as possible in my code, so I'll try eskimo's [2] first).

Thank you for clarifying,

Matthias