macOS – How Unix File Permissions are Stored in ZIP Files

archivefinderjavapermissionzip

I am trying to extract a ZIP file in Java which was created on a Mac using the built-in archive functionality of the Finder. As the ZIP file contains an application bundle, it is important to retain the Unix file permissions, especially the executable flag.

When extracting the ZIP file using the Finder, the permissions are retained. So I know they're stored somewhere in there.

Now my question is: how does macOS store Unix file permissions in ZIP files? Unfortunately I could not find any information about this on the net.

Best Answer

The permissions are stored in the same manner as they are on other Unixoid systems, such as for example Linux.

If you look at the central directory header in the zip-file, you have for each file stored in the Zip-file a field called "external file attributes". The field is at byte 36 in the header and is 4 bytes long.

The two last bytes in that field contains the file permissions on macOS - to be precise it is the last 9 bits (the least significant 9 bits). Their meaning is just like traditional Unix file permissions.