A xar archive is a binary header, a zlib-compressed XML table of contents, and a heap
that holds everything else. The header, the heap and the TOC elements are taken from libxar’s source (the
mackyle/xar copy: xar.h.in, archive.c, stat.c,
signature.c, darwinattr.c, io.c, zxar.c, bzxar.c,
lzmaxar.c, ea.c), read raw on 2026-11-13 and again on 2026-11-19. The project’s wiki pages
(xarformat, metadata_stat, metadata_chflags, ArchivedMetadata) were cited
here on 2026-11-13, but their text could not be fetched as a raw file on 2026-11-19 (the raw wiki addresses answer 404), so anything on this page that rests
only on them is from the wiki, unverified.
Header
Big-endian.
| Offset | Size | Name | Description |
|---|---|---|---|
0 | 4 | magic | 78 61 72 21, xar!. |
4 | 2 | size | Size of the header, magic included. At least 28. |
6 | 2 | version | 1. libxar writes 1 and ignores the value when reading; libarchive refuses any other, and 7-Zip accepts 0 (some old archives) and 1. |
8 | 8 | toc_length_compressed | Length of the compressed table of contents. |
16 | 8 | toc_length_uncompressed | Length of the table of contents after decompression. |
24 | 4 | cksum_alg | Checksum of the table of contents: 0 none, 1 SHA-1, 2 MD5, 3 SHA-256 (macOS’s xar, libarchive, 7-Zip) or “another, named next” (libxar), 4 SHA-512 (macOS’s xar, libarchive, 7-Zip). |
28 | … | name | Only in libxar’s form of cksum_alg 3: the algorithm’s name, NUL-terminated, padded with zeros to a multiple of 4. |
Algorithm 3 has two forms. macOS’s own xar (1.8dev) writes --toc-cksum sha256 archives
with 3 and sha512 archives with 4, in an ordinary 28-byte header; its
--dump-header prints “3 (SHA256)” and “4 (SHA512)”, and libarchive and 7-Zip read the codes the same way. In the
open-source libxar’s xar.h, 3 means “another digest, named in the header”: size must then be a multiple
of 4 and at least 32; the name must not be empty or none, should not be sha1 or md5 (use 1
or 2), and must match the style of the TOC’s checksum element byte for byte. That libxar
writes a 64-byte header in this case, so the name can be up to 35 characters and the NUL (toc_cksum_name[36]), and it defines no 4. 7-Zip’s source says
it does not support a digest named in the header. A reader that meets 3 in a 28-byte header should take SHA-256, and in
a longer one the name that follows.
The compressed table of contents follows the header at offset size,
exactly toc_length_compressed bytes of zlib data (RFC 1950). The checksum
is taken over these compressed bytes.
Heap
- The heap starts right after the compressed table of contents. Every
offsetin the TOC counts from the start of the heap. - The TOC checksum is normally first: the TOC’s
checksumelement gives its offset (usually 0) and size (20 for SHA-1, 16 for MD5). - For each stored stream,
lengthis the number of bytes in the heap andsizethe size after decoding. - For an archive that can be read as a stream, all of one file’s heap entries are together, and its extended attributes come before its data, so the security context is set before the data is written.
Table of contents
A UTF-8 XML document whose root is xar, holding one toc.
| Element | In | Meaning |
|---|---|---|
checksum, attribute style | toc | Where the TOC checksum is in the heap: child offset and size. style is sha1, md5 or the name in the header. |
creation-time | toc | When the archive was made (libxar; ISO 8601 text). |
signature, attribute style | toc | A signature of the TOC checksum, stored in the heap at child offset and size. libxar writes the signature type into the style attribute (its source comment shows style="SHA1withRSA"; every signed package seen has style="RSA") and the signer’s certificates in a KeyInfo / X509Data / X509Certificate chain in the XML Signature namespace (http://www.w3.org/2000/09/xmldsig#). Not in the wiki page. |
x-signature, attribute style | toc | A second signature, style="CMS", written by recent macOS tools after the signature: the same offset, size and KeyInfo children, with a CMS SignedData in the heap. Seen in a real Developer ID package (a 9,216-byte CMS block at heap offset 276, after the 20-byte checksum and the 256-byte RSA signature). libxar’s source has no such element. See Checksums and signature. |
subdoc, attribute subdoc_name | xar, beside toc | A subdocument: libxar lets a program keep its own XML in the table of contents (xar_subdoc_new, subdoc.c). It is written before toc as <subdoc subdoc_name="NAME" xmlns="NAMESPACE"> with the subdocument’s own elements inside (its attributes, element text and children are kept). When libxar reads an element of xar that is not toc, it makes a subdocument of it, named by its subdoc_name attribute or, without one, by the element’s own name. libarchive skips these elements; 7-Zip refuses an archive whose xar has more than the one child toc. No archive with a subdocument was available to check. |
file, attribute id | toc or another file | One archive member. A folder’s members are nested inside its file element. id is a unique number. |
Inside file
| Element | Meaning |
|---|---|
name | The name, without the path (the nesting gives the path). An attribute enctype="base64" says the text is base64 of the UTF-8 name (libarchive reads it). The packages made by macOS’s pkgbuild and productbuild, seen on one Mac, hold this element twice in every file with the same text; the readers use the first. |
type | file, directory, symlink, hardlink, fifo, character special, block special, socket or whiteout (libxar). A hard link has link="original" on the first copy and link="id" on the others. |
link | Target of a symbolic link, with type="file", "directory" or "broken". |
mode | Permission bits, in octal text, such as 0755. |
uid, gid | Numeric owner and group. |
user, group | Owner and group names. |
atime, mtime, ctime | Times in ISO 8601, such as 2024-05-01T12:00:00Z. |
size | Size of the file. |
inode, deviceno, nlink | Inode number, device number and link count (libxar). |
device | For device files: children major and minor (libxar). |
flags | The chflags(2) file flags where the system has them, one child element per flag set. The names libxar writes: UserNoDump, UserImmutable, UserAppend, UserOpaque, UserNoUnlink, UserCompressed, UserTracked, UserHidden, SystemArchived, SystemImmutable, SystemAppend, SystemNoUnlink, SystemSnapshot. The wiki’s metadata page lists only the first six kinds (User No Dump, User Immutable, User Append, User Opaque, System Archived, System Immutable). |
acl | The file’s access control list, as text in one child: appleextended (macOS: the text acl_to_text gives, !#acl 1 and then one entry a line, user or group, the GUID, the name, the numeric id, allow or deny followed by any inheritance flags (file_inherit, directory_inherit, limit_inherit, only_inherit, inherited), and the permissions: group:ABCDEFAB-CDEF-ABCD-EFAB-CDEF0000000C:everyone:12:deny:delete), or access and default (other systems: a POSIX ACL as acl_to_text writes it, user::rw- lines or the short u::rwx,g::r-x,o::r-x form). libxar writes appleextended on macOS and the other two elsewhere (stat.c); libarchive reads all three. |
ext2 | The ext2 file system’s attributes (chattr): the attribute version is the file’s ext2 version number, and libarchive reads one empty child element for each attribute set: SecureDeletion, Undelete, Compress, Synchronous, Immutable, AppendOnly, NoDump, NoAtime, CompDirty, CompBlock, NoCompBlock, CompError, BTree, HashIndexed, iMagic, Journaled, NoTail, DirSync, TopDir, Reserved. libxar’s own writer (ext2.c) puts them in a sibling element called attribute (<attribute><NoDump fstype="ext2"/>), so the two do not read each other’s files; both forms are decoded. libxar writes ext2 only on Linux with the ext2 headers, only for files, hard links and directories, and only when a flag is set. |
FinderCreateTime | The Mac creation date: children time and nanoseconds (libxar on macOS). In archives made by macOS’s xar the time text is not a date in the form of the other times: values such as 1900-01-00T16:23:28 (day 00) were seen in archives made for this site’s tests, so it is not a time to rely on. |
data | The file’s contents in the heap: see data. |
ea, attribute id | One extended attribute, such as com.apple.ResourceFork or com.apple.FinderInfo: child name and the same children as data. |
Inside data and ea
| Element | Meaning |
|---|---|
offset | Where the stored bytes start, from the start of the heap. |
length | How many bytes are stored. |
size | How many bytes they decode to. |
encoding, attribute style | How the bytes are stored, as a MIME type: application/octet-stream (stored), application/x-gzip (zlib data, despite the name; libxar writes application/zlib instead when its “RFC format” option is on), application/x-bzip2, application/x-lzma or application/x-xz (libxar’s set; the wiki shows only application/x-gzip). |
archived-checksum, attribute style | Checksum of the stored bytes, in hexadecimal text. |
extracted-checksum, attribute style | Checksum of the decoded bytes. |
Example
<xar>
<toc>
<checksum style="sha1"><offset>0</offset><size>20</size></checksum>
<file id="1">
<name>hello.txt</name>
<type>file</type>
<mode>0644</mode>
<uid>501</uid><user>lew</user><gid>20</gid><group>staff</group>
<mtime>2024-05-01T12:00:00Z</mtime>
<data>
<offset>20</offset><length>26</length><size>14</size>
<encoding style="application/x-gzip"/>
<archived-checksum style="sha1">…</archived-checksum>
<extracted-checksum style="sha1">…</extracted-checksum>
</data>
</file>
</toc>
</xar>
An illustration put together for this page: the heap holds the 20-byte SHA-1 of the compressed TOC at offset 0, then the file’s 26 bytes of zlib data.