A .bag
file (short for "Blobby/Binary/Boxed/Bagged Atom Graph") file describes a directed graph of atoms, which can be either blob (array of bytes) or cell (array of atoms) in topological order of ownership, leaves first, root last. This renders the format particularly append/overlay-friendly, as the root can be rewritten without changing the existing file or removing unused nodes.
.bag
is comparable to RIFF in scope but fixes two major problems with it, namely that RIFF can only encode trees and isn't topologically ordered, requiring the use of a stack when reading it.
The format can be read as a binary stream of 64-bit words. It begins with the magic 4-character sequence .bag
and a 32-bit version which must be 1
(hence .bag\x01\0\0\0
or 0x000000016761622e
), and is then only followed by atoms until the file ends.
An atom begins with a header word, followed by its contents, aligned t