Nix Archive (NAR) is the archive format of the Nix package manager. A NAR contains a single file system object: a regular file, a symbolic link, or a directory with everything in it. Besides names, file contents and symlink targets, it only stores which regular files are executable. There are no timestamps and no other permissions.
Unlike TAR or ZIP, the format is canonical: a given file system object always has the same NAR. For example, directory entries are always sorted by name. Nix identifies the contents of each store path by the SHA-256 hash of its NAR, and binary caches serve store paths as NARs, usually compressed. GNU Guix uses the same format.
This Kaitai Struct implementation rejects the same NARs as Nix 2.36.0
with the default settings on Linux, except that it accepts entry names
that contain /.
Older versions of Nix may accept more NARs. For example, Nix checks the order of directory entries only since version 2.25.0, and it limits the length of names and symlink targets and the nesting depth only since 2.35.0. Some of these checks were also backported to patch releases of older versions.
This page hosts a formal specification of Nix Archive (NAR) using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.
All C++98/STL code generated by Kaitai Struct depends on the Kaitai Struct runtime library for C++/STL. You must add this dependency to your project before you can parse or serialize any data.
For C++, the easiest way is to clone the runtime library sources and build them along with your project.
Using Kaitai Struct in C++/STL usually consists of 3 steps.
std::istream). One can open local file for that, or use existing std::string or char* buffer.
#include <fstream>
std::ifstream is("path/to/local/file.nar", std::ifstream::binary);
#include <sstream>
std::istringstream is(str);
#include <sstream>
const char buf[] = { ... };
std::string str(buf, sizeof buf);
std::istringstream is(str);
#include "kaitai/kaitaistream.h"
kaitai::kstream ks(&is);
nix_nar_t data(&ks);
After that, one can get various attributes from the structure by invoking getter methods like:
data.magic() // => Magic string, must be `nix-archive-1`.
#ifndef NIX_NAR_H_
#define NIX_NAR_H_
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
class nix_nar_t;
#include "kaitai/kaitaistruct.h"
#include <stdint.h>
#include <vector>
#if KAITAI_STRUCT_VERSION < 11000L
#error "Incompatible Kaitai Struct C++/STL API: version 0.11 or later is required"
#endif
/**
* Nix Archive (NAR) is the archive format of the [Nix](https://nixos.org/)
* package manager. A NAR contains a single file system object: a regular
* file, a symbolic link, or a directory with everything in it. Besides
* names, file contents and symlink targets, it only stores which regular
* files are executable. There are
* [no timestamps and no other permissions](https://github.com/NixOS/nix/blob/88907193c54fcd5184cf59d14b693188e2875168/doc/manual/source/command-ref/nix-store/dump.md?plain=1#L15-L19).
*
* Unlike TAR or ZIP, the format is
* [canonical](https://github.com/NixOS/nix/blob/88907193c54fcd5184cf59d14b693188e2875168/doc/manual/source/command-ref/nix-store/dump.md?plain=1#L21-L27):
* a given file system object always has the same NAR. For example,
* directory entries are always sorted by name. Nix identifies the contents
* of each store path by the SHA-256 hash of its NAR, and
* [binary caches](https://github.com/NixOS/nix/blob/88907193c54fcd5184cf59d14b693188e2875168/doc/manual/source/protocols/binary-cache/index.md?plain=1#L8-L10)
* serve store paths as NARs, usually compressed.
* [GNU Guix](https://codeberg.org/guix/guix/src/commit/ab6a9f84e783710335a29f6591f570e5e2df143c/guix/serialization.scm#L441-L446)
* uses the same format.
*
* This Kaitai Struct implementation rejects the same NARs as Nix 2.36.0
* with the default settings on Linux, except that it accepts entry names
* that contain `/`.
*
* Older versions of Nix may accept more NARs. For example, Nix checks the
* order of directory entries only since version 2.25.0, and it limits the
* length of names and symlink targets and the nesting depth only since
* 2.35.0. Some of these checks were also backported to patch releases of
* older versions.
* \sa https://github.com/NixOS/nix/blob/88907193c54fcd5184cf59d14b693188e2875168/doc/manual/source/protocols/nix-archive/index.md Git tag "2.36.0"
*/
class nix_nar_t : public kaitai::kstruct {
public:
class node_t;
class padded_bytes_t;
class padded_str_t;
class type_directory_t;
class type_regular_t;
class type_symlink_t;
nix_nar_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = 0, nix_nar_t* p__root = 0);
private:
void _read();
void _clean_up();
public:
~nix_nar_t();
/**
* A single file system node (regular file, directory, or symlink).
*/
class node_t : public kaitai::kstruct {
public:
node_t(int32_t p_depth, kaitai::kstream* p__io, kaitai::kstruct* p__parent = 0, nix_nar_t* p__root = 0);
private:
void _read();
void _clean_up();
public:
~node_t();
private:
std::string m__unnamed0;
padded_str_t* m_open_paren;
padded_str_t* m_type_key;
padded_str_t* m_type_val;
kaitai::kstruct* m_body;
bool n_body;
public:
bool _is_null_body() { body(); return n_body; };
private:
padded_str_t* m_close_paren;
bool n_close_paren;
public:
bool _is_null_close_paren() { close_paren(); return n_close_paren; };
private:
int32_t m_depth;
nix_nar_t* m__root;
kaitai::kstruct* m__parent;
public:
std::string _unnamed0() const { return m__unnamed0; }
/**
* Must be `(`, a token starting the node definition.
*/
padded_str_t* open_paren() const { return m_open_paren; }
/**
* Must be `type`.
*/
padded_str_t* type_key() const { return m_type_key; }
/**
* Type of the node (`regular`, `directory`, or `symlink`).
*/
padded_str_t* type_val() const { return m_type_val; }
kaitai::kstruct* body() const { return m_body; }
/**
* Must be `)`, a token ending the node definition. A directory node
* has no `close_paren`: its `)` is read as the terminator at the end
* of `body.entries`.
*/
padded_str_t* close_paren() const { return m_close_paren; }
/**
* Nesting depth of the node. The root node has depth 0.
*/
int32_t depth() const { return m_depth; }
nix_nar_t* _root() const { return m__root; }
kaitai::kstruct* _parent() const { return m__parent; }
};
/**
* A byte sequence, prefixed with its length (u8le) and
* padded with null bytes to the next 8-byte boundary.
*
* Used for entry names and symlink targets, which Nix handles as raw
* bytes, without decoding them as text.
*/
class padded_bytes_t : public kaitai::kstruct {
public:
padded_bytes_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = 0, nix_nar_t* p__root = 0);
private:
void _read();
void _clean_up();
public:
~padded_bytes_t();
private:
uint64_t m_len_body;
std::string m_body;
std::string m_padding;
nix_nar_t* m__root;
kaitai::kstruct* m__parent;
public:
uint64_t len_body() const { return m_len_body; }
std::string body() const { return m_body; }
std::string padding() const { return m_padding; }
nix_nar_t* _root() const { return m__root; }
kaitai::kstruct* _parent() const { return m__parent; }
};
/**
* A string, prefixed with its length (u8le) and
* padded with null bytes to the next 8-byte boundary.
*
* Used for the tokens of the format, such as `nix-archive-1`, `(` and
* `type`. They are all ASCII.
*/
class padded_str_t : public kaitai::kstruct {
public:
padded_str_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = 0, nix_nar_t* p__root = 0);
private:
void _read();
void _clean_up();
public:
~padded_str_t();
private:
uint64_t m_len_body;
std::string m_body;
std::string m_padding;
nix_nar_t* m__root;
kaitai::kstruct* m__parent;
public:
uint64_t len_body() const { return m_len_body; }
std::string body() const { return m_body; }
std::string padding() const { return m_padding; }
nix_nar_t* _root() const { return m__root; }
kaitai::kstruct* _parent() const { return m__parent; }
};
/**
* A directory node, containing a list of entries. Entries must be
* ordered by their names. Each name must be greater than the previous
* one when compared lexicographically as arrays of unsigned bytes.
*/
class type_directory_t : public kaitai::kstruct {
public:
class dir_entry_t;
class dir_entry_body_t;
type_directory_t(kaitai::kstream* p__io, nix_nar_t::node_t* p__parent = 0, nix_nar_t* p__root = 0);
private:
void _read();
void _clean_up();
public:
~type_directory_t();
/**
* A single entry within a directory, or the terminator, i.e. the `)`
* token that ends the directory node.
*/
class dir_entry_t : public kaitai::kstruct {
public:
dir_entry_t(kaitai::kstream* p__io, nix_nar_t::type_directory_t* p__parent = 0, nix_nar_t* p__root = 0);
private:
void _read();
void _clean_up();
public:
~dir_entry_t();
private:
bool f_is_terminator;
bool m_is_terminator;
public:
bool is_terminator();
private:
padded_str_t* m_kind;
dir_entry_body_t* m_body;
bool n_body;
public:
bool _is_null_body() { body(); return n_body; };
private:
nix_nar_t* m__root;
nix_nar_t::type_directory_t* m__parent;
public:
/**
* Must be `entry` (for a child node) or `)` (for the terminator).
*/
padded_str_t* kind() const { return m_kind; }
/**
* The entry itself. The terminator has no `body`.
*/
dir_entry_body_t* body() const { return m_body; }
nix_nar_t* _root() const { return m__root; }
nix_nar_t::type_directory_t* _parent() const { return m__parent; }
};
class dir_entry_body_t : public kaitai::kstruct {
public:
dir_entry_body_t(kaitai::kstream* p__io, nix_nar_t::type_directory_t::dir_entry_t* p__parent = 0, nix_nar_t* p__root = 0);
private:
void _read();
void _clean_up();
public:
~dir_entry_body_t();
private:
padded_str_t* m_open_paren;
padded_str_t* m_name_key;
padded_bytes_t* m_name;
padded_str_t* m_node_key;
node_t* m_node;
padded_str_t* m_close_paren;
nix_nar_t* m__root;
nix_nar_t::type_directory_t::dir_entry_t* m__parent;
public:
padded_str_t* open_paren() const { return m_open_paren; }
padded_str_t* name_key() const { return m_name_key; }
/**
* Name of the entry, as raw bytes. Nix 2.36.0
* [doesn't decode names as text](https://github.com/NixOS/nix/blob/88907193c54fcd5184cf59d14b693188e2875168/src/libutil/archive.cc#L245-L248)
* either, and real NARs contain names that aren't valid UTF-8.
*
* The name must be 1 to 255 bytes long, must not be `.` or `..`, and
* must not contain a null byte. Nix also rejects names that contain
* `/`, but this Kaitai Struct implementation doesn't check that: as
* of KS 0.11, expressions can't search a byte array for a given
* byte. A null byte can be detected anyway: 0 is the smallest
* possible byte value, so a name contains a null byte exactly if its
* smallest byte is 0.
*/
padded_bytes_t* name() const { return m_name; }
padded_str_t* node_key() const { return m_node_key; }
/**
* The child node.
*/
node_t* node() const { return m_node; }
padded_str_t* close_paren() const { return m_close_paren; }
nix_nar_t* _root() const { return m__root; }
nix_nar_t::type_directory_t::dir_entry_t* _parent() const { return m__parent; }
};
private:
std::vector<dir_entry_t*>* m_entries;
nix_nar_t* m__root;
nix_nar_t::node_t* m__parent;
public:
std::vector<dir_entry_t*>* entries() const { return m_entries; }
nix_nar_t* _root() const { return m__root; }
nix_nar_t::node_t* _parent() const { return m__parent; }
};
/**
* A regular file node.
*/
class type_regular_t : public kaitai::kstruct {
public:
class file_content_t;
type_regular_t(kaitai::kstream* p__io, nix_nar_t::node_t* p__parent = 0, nix_nar_t* p__root = 0);
private:
void _read();
void _clean_up();
public:
~type_regular_t();
/**
* The contents of the file, prefixed with their length and padded
* with null bytes to the next 8-byte boundary.
*/
class file_content_t : public kaitai::kstruct {
public:
file_content_t(kaitai::kstream* p__io, nix_nar_t::type_regular_t* p__parent = 0, nix_nar_t* p__root = 0);
private:
void _read();
void _clean_up();
public:
~file_content_t();
private:
bool f_nar_offset;
int32_t m_nar_offset;
public:
/**
* Offset of `contents` in the stream. It corresponds to
* [`narOffset`](https://github.com/NixOS/nix/blob/88907193c54fcd5184cf59d14b693188e2875168/src/libutil/include/nix/util/source-accessor.hh#L134-L138)
* in Nix.
*/
int32_t nar_offset();
private:
uint64_t m_len_contents;
std::string m__unnamed1;
bool n__unnamed1;
public:
bool _is_null__unnamed1() { _unnamed1(); return n__unnamed1; };
private:
std::string m_contents;
std::string m_padding;
nix_nar_t* m__root;
nix_nar_t::type_regular_t* m__parent;
public:
uint64_t len_contents() const { return m_len_contents; }
std::string _unnamed1() const { return m__unnamed1; }
/**
* This Kaitai Struct implementation keeps the contents of every
* file in memory, so parsing a NAR needs at least as much memory
* as all its files together.
*/
std::string contents() const { return m_contents; }
std::string padding() const { return m_padding; }
nix_nar_t* _root() const { return m__root; }
nix_nar_t::type_regular_t* _parent() const { return m__parent; }
};
private:
bool f_is_executable;
bool m_is_executable;
public:
/**
* True if the file has the `executable` attribute.
*/
bool is_executable();
private:
padded_str_t* m_first_key;
padded_str_t* m_executable_val;
bool n_executable_val;
public:
bool _is_null_executable_val() { executable_val(); return n_executable_val; };
private:
padded_str_t* m_contents_key;
bool n_contents_key;
public:
bool _is_null_contents_key() { contents_key(); return n_contents_key; };
private:
file_content_t* m_file_data;
nix_nar_t* m__root;
nix_nar_t::node_t* m__parent;
public:
/**
* Either `executable` or `contents`.
*/
padded_str_t* first_key() const { return m_first_key; }
/**
* Must be empty.
*/
padded_str_t* executable_val() const { return m_executable_val; }
padded_str_t* contents_key() const { return m_contents_key; }
file_content_t* file_data() const { return m_file_data; }
nix_nar_t* _root() const { return m__root; }
nix_nar_t::node_t* _parent() const { return m__parent; }
};
/**
* A symbolic link node.
*/
class type_symlink_t : public kaitai::kstruct {
public:
type_symlink_t(kaitai::kstream* p__io, nix_nar_t::node_t* p__parent = 0, nix_nar_t* p__root = 0);
private:
void _read();
void _clean_up();
public:
~type_symlink_t();
private:
padded_str_t* m_target_key;
padded_bytes_t* m_target_val;
nix_nar_t* m__root;
nix_nar_t::node_t* m__parent;
public:
/**
* Must be `target`.
*/
padded_str_t* target_key() const { return m_target_key; }
/**
* The destination path of the symlink, as raw bytes. Nix 2.36.0
* [doesn't decode targets as text](https://github.com/NixOS/nix/blob/88907193c54fcd5184cf59d14b693188e2875168/src/libutil/archive.cc#L280-L282)
* either.
*
* The target must be 1 to 4095 bytes long and must not contain a null
* byte.
*/
padded_bytes_t* target_val() const { return m_target_val; }
nix_nar_t* _root() const { return m__root; }
nix_nar_t::node_t* _parent() const { return m__parent; }
};
private:
padded_str_t* m_magic;
node_t* m_root_node;
nix_nar_t* m__root;
kaitai::kstruct* m__parent;
public:
/**
* Magic string, must be `nix-archive-1`.
*/
padded_str_t* magic() const { return m_magic; }
/**
* The root of the archive, which is always a single node.
*/
node_t* root_node() const { return m_root_node; }
nix_nar_t* _root() const { return m__root; }
kaitai::kstruct* _parent() const { return m__parent; }
};
#endif // NIX_NAR_H_
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "nix_nar.h"
#include "kaitai/exceptions.h"
nix_nar_t::nix_nar_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, nix_nar_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root ? p__root : this;
m_magic = 0;
m_root_node = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void nix_nar_t::_read() {
m_magic = new padded_str_t(m__io, this, m__root);
{
padded_str_t* _ = m_magic;
if (!(_->body() == std::string("nix-archive-1"))) {
throw kaitai::validation_expr_error<nix_nar_t::padded_str_t*>(m_magic, m__io, std::string("/seq/0"));
}
}
m_root_node = new node_t(0, m__io, this, m__root);
}
nix_nar_t::~nix_nar_t() {
_clean_up();
}
void nix_nar_t::_clean_up() {
if (m_magic) {
delete m_magic; m_magic = 0;
}
if (m_root_node) {
delete m_root_node; m_root_node = 0;
}
}
nix_nar_t::node_t::node_t(int32_t p_depth, kaitai::kstream* p__io, kaitai::kstruct* p__parent, nix_nar_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_depth = p_depth;
m_open_paren = 0;
m_type_key = 0;
m_type_val = 0;
m_close_paren = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void nix_nar_t::node_t::_read() {
m__unnamed0 = m__io->read_bytes(0);
{
std::string _ = m__unnamed0;
if (!(depth() < 64)) {
throw kaitai::validation_expr_error<std::string>(m__unnamed0, m__io, std::string("/types/node/seq/0"));
}
}
m_open_paren = new padded_str_t(m__io, this, m__root);
{
padded_str_t* _ = m_open_paren;
if (!(_->body() == std::string("("))) {
throw kaitai::validation_expr_error<nix_nar_t::padded_str_t*>(m_open_paren, m__io, std::string("/types/node/seq/1"));
}
}
m_type_key = new padded_str_t(m__io, this, m__root);
{
padded_str_t* _ = m_type_key;
if (!(_->body() == std::string("type"))) {
throw kaitai::validation_expr_error<nix_nar_t::padded_str_t*>(m_type_key, m__io, std::string("/types/node/seq/2"));
}
}
m_type_val = new padded_str_t(m__io, this, m__root);
{
padded_str_t* _ = m_type_val;
if (!( ((_->body() == std::string("regular")) || (_->body() == std::string("directory")) || (_->body() == std::string("symlink"))) )) {
throw kaitai::validation_expr_error<nix_nar_t::padded_str_t*>(m_type_val, m__io, std::string("/types/node/seq/3"));
}
}
n_body = true;
{
std::string on = type_val()->body();
if (on == std::string("directory")) {
n_body = false;
m_body = new type_directory_t(m__io, this, m__root);
}
else if (on == std::string("regular")) {
n_body = false;
m_body = new type_regular_t(m__io, this, m__root);
}
else if (on == std::string("symlink")) {
n_body = false;
m_body = new type_symlink_t(m__io, this, m__root);
}
}
n_close_paren = true;
if (type_val()->body() != std::string("directory")) {
n_close_paren = false;
m_close_paren = new padded_str_t(m__io, this, m__root);
{
padded_str_t* _ = m_close_paren;
if (!(_->body() == std::string(")"))) {
throw kaitai::validation_expr_error<nix_nar_t::padded_str_t*>(m_close_paren, m__io, std::string("/types/node/seq/5"));
}
}
}
}
nix_nar_t::node_t::~node_t() {
_clean_up();
}
void nix_nar_t::node_t::_clean_up() {
if (m_open_paren) {
delete m_open_paren; m_open_paren = 0;
}
if (m_type_key) {
delete m_type_key; m_type_key = 0;
}
if (m_type_val) {
delete m_type_val; m_type_val = 0;
}
if (!n_body) {
if (m_body) {
delete m_body; m_body = 0;
}
}
if (!n_close_paren) {
if (m_close_paren) {
delete m_close_paren; m_close_paren = 0;
}
}
}
nix_nar_t::padded_bytes_t::padded_bytes_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, nix_nar_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void nix_nar_t::padded_bytes_t::_read() {
m_len_body = m__io->read_u8le();
m_body = m__io->read_bytes(len_body());
m_padding = m__io->read_bytes(kaitai::kstream::mod(8 - kaitai::kstream::mod(len_body(), 8), 8));
{
std::string _ = m_padding;
if (!(((_.length() != 0) ? (kaitai::kstream::byte_array_max(_) == 0) : (true)))) {
throw kaitai::validation_expr_error<std::string>(m_padding, m__io, std::string("/types/padded_bytes/seq/2"));
}
}
}
nix_nar_t::padded_bytes_t::~padded_bytes_t() {
_clean_up();
}
void nix_nar_t::padded_bytes_t::_clean_up() {
}
nix_nar_t::padded_str_t::padded_str_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, nix_nar_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void nix_nar_t::padded_str_t::_read() {
m_len_body = m__io->read_u8le();
m_body = kaitai::kstream::bytes_to_str(m__io->read_bytes(len_body()), "ASCII");
m_padding = m__io->read_bytes(kaitai::kstream::mod(8 - kaitai::kstream::mod(len_body(), 8), 8));
{
std::string _ = m_padding;
if (!(((_.length() != 0) ? (kaitai::kstream::byte_array_max(_) == 0) : (true)))) {
throw kaitai::validation_expr_error<std::string>(m_padding, m__io, std::string("/types/padded_str/seq/2"));
}
}
}
nix_nar_t::padded_str_t::~padded_str_t() {
_clean_up();
}
void nix_nar_t::padded_str_t::_clean_up() {
}
nix_nar_t::type_directory_t::type_directory_t(kaitai::kstream* p__io, nix_nar_t::node_t* p__parent, nix_nar_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_entries = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void nix_nar_t::type_directory_t::_read() {
m_entries = new std::vector<dir_entry_t*>();
{
int i = 0;
dir_entry_t* _;
do {
_ = new dir_entry_t(m__io, this, m__root);
m_entries->push_back(_);
{
dir_entry_t* _ = m_entries->at(i);
if (!((( ((i != 0) && (!(_->is_terminator()))) ) ? (_->body()->name()->body() > entries()->at(i - 1)->body()->name()->body()) : (true)))) {
throw kaitai::validation_expr_error<nix_nar_t::type_directory_t::dir_entry_t*>(m_entries->at(i), m__io, std::string("/types/type_directory/seq/0"));
}
}
i++;
} while (!(_->is_terminator()));
}
}
nix_nar_t::type_directory_t::~type_directory_t() {
_clean_up();
}
void nix_nar_t::type_directory_t::_clean_up() {
if (m_entries) {
for (std::vector<dir_entry_t*>::iterator it = m_entries->begin(); it != m_entries->end(); ++it) {
delete *it;
}
delete m_entries; m_entries = 0;
}
}
nix_nar_t::type_directory_t::dir_entry_t::dir_entry_t(kaitai::kstream* p__io, nix_nar_t::type_directory_t* p__parent, nix_nar_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_kind = 0;
m_body = 0;
f_is_terminator = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void nix_nar_t::type_directory_t::dir_entry_t::_read() {
m_kind = new padded_str_t(m__io, this, m__root);
{
padded_str_t* _ = m_kind;
if (!( ((_->body() == std::string("entry")) || (_->body() == std::string(")"))) )) {
throw kaitai::validation_expr_error<nix_nar_t::padded_str_t*>(m_kind, m__io, std::string("/types/type_directory/types/dir_entry/seq/0"));
}
}
n_body = true;
if (!(is_terminator())) {
n_body = false;
m_body = new dir_entry_body_t(m__io, this, m__root);
}
}
nix_nar_t::type_directory_t::dir_entry_t::~dir_entry_t() {
_clean_up();
}
void nix_nar_t::type_directory_t::dir_entry_t::_clean_up() {
if (m_kind) {
delete m_kind; m_kind = 0;
}
if (!n_body) {
if (m_body) {
delete m_body; m_body = 0;
}
}
}
bool nix_nar_t::type_directory_t::dir_entry_t::is_terminator() {
if (f_is_terminator)
return m_is_terminator;
f_is_terminator = true;
m_is_terminator = kind()->body() == std::string(")");
return m_is_terminator;
}
nix_nar_t::type_directory_t::dir_entry_body_t::dir_entry_body_t(kaitai::kstream* p__io, nix_nar_t::type_directory_t::dir_entry_t* p__parent, nix_nar_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_open_paren = 0;
m_name_key = 0;
m_name = 0;
m_node_key = 0;
m_node = 0;
m_close_paren = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void nix_nar_t::type_directory_t::dir_entry_body_t::_read() {
m_open_paren = new padded_str_t(m__io, this, m__root);
{
padded_str_t* _ = m_open_paren;
if (!(_->body() == std::string("("))) {
throw kaitai::validation_expr_error<nix_nar_t::padded_str_t*>(m_open_paren, m__io, std::string("/types/type_directory/types/dir_entry_body/seq/0"));
}
}
m_name_key = new padded_str_t(m__io, this, m__root);
{
padded_str_t* _ = m_name_key;
if (!(_->body() == std::string("name"))) {
throw kaitai::validation_expr_error<nix_nar_t::padded_str_t*>(m_name_key, m__io, std::string("/types/type_directory/types/dir_entry_body/seq/1"));
}
}
m_name = new padded_bytes_t(m__io, this, m__root);
{
padded_bytes_t* _ = m_name;
if (!( ((_->body().length() != 0) && (_->body().length() <= 255) && (_->body() != std::string("\x2E", 1)) && (_->body() != std::string("\x2E\x2E", 2)) && (kaitai::kstream::byte_array_min(_->body()) != 0)) )) {
throw kaitai::validation_expr_error<nix_nar_t::padded_bytes_t*>(m_name, m__io, std::string("/types/type_directory/types/dir_entry_body/seq/2"));
}
}
m_node_key = new padded_str_t(m__io, this, m__root);
{
padded_str_t* _ = m_node_key;
if (!(_->body() == std::string("node"))) {
throw kaitai::validation_expr_error<nix_nar_t::padded_str_t*>(m_node_key, m__io, std::string("/types/type_directory/types/dir_entry_body/seq/3"));
}
}
m_node = new node_t(_parent()->_parent()->_parent()->depth() + 1, m__io, this, m__root);
m_close_paren = new padded_str_t(m__io, this, m__root);
{
padded_str_t* _ = m_close_paren;
if (!(_->body() == std::string(")"))) {
throw kaitai::validation_expr_error<nix_nar_t::padded_str_t*>(m_close_paren, m__io, std::string("/types/type_directory/types/dir_entry_body/seq/5"));
}
}
}
nix_nar_t::type_directory_t::dir_entry_body_t::~dir_entry_body_t() {
_clean_up();
}
void nix_nar_t::type_directory_t::dir_entry_body_t::_clean_up() {
if (m_open_paren) {
delete m_open_paren; m_open_paren = 0;
}
if (m_name_key) {
delete m_name_key; m_name_key = 0;
}
if (m_name) {
delete m_name; m_name = 0;
}
if (m_node_key) {
delete m_node_key; m_node_key = 0;
}
if (m_node) {
delete m_node; m_node = 0;
}
if (m_close_paren) {
delete m_close_paren; m_close_paren = 0;
}
}
nix_nar_t::type_regular_t::type_regular_t(kaitai::kstream* p__io, nix_nar_t::node_t* p__parent, nix_nar_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_first_key = 0;
m_executable_val = 0;
m_contents_key = 0;
m_file_data = 0;
f_is_executable = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void nix_nar_t::type_regular_t::_read() {
m_first_key = new padded_str_t(m__io, this, m__root);
{
padded_str_t* _ = m_first_key;
if (!( ((_->body() == std::string("executable")) || (_->body() == std::string("contents"))) )) {
throw kaitai::validation_expr_error<nix_nar_t::padded_str_t*>(m_first_key, m__io, std::string("/types/type_regular/seq/0"));
}
}
n_executable_val = true;
if (is_executable()) {
n_executable_val = false;
m_executable_val = new padded_str_t(m__io, this, m__root);
{
padded_str_t* _ = m_executable_val;
if (!(_->body() == std::string(""))) {
throw kaitai::validation_expr_error<nix_nar_t::padded_str_t*>(m_executable_val, m__io, std::string("/types/type_regular/seq/1"));
}
}
}
n_contents_key = true;
if (is_executable()) {
n_contents_key = false;
m_contents_key = new padded_str_t(m__io, this, m__root);
{
padded_str_t* _ = m_contents_key;
if (!(_->body() == std::string("contents"))) {
throw kaitai::validation_expr_error<nix_nar_t::padded_str_t*>(m_contents_key, m__io, std::string("/types/type_regular/seq/2"));
}
}
}
m_file_data = new file_content_t(m__io, this, m__root);
}
nix_nar_t::type_regular_t::~type_regular_t() {
_clean_up();
}
void nix_nar_t::type_regular_t::_clean_up() {
if (m_first_key) {
delete m_first_key; m_first_key = 0;
}
if (!n_executable_val) {
if (m_executable_val) {
delete m_executable_val; m_executable_val = 0;
}
}
if (!n_contents_key) {
if (m_contents_key) {
delete m_contents_key; m_contents_key = 0;
}
}
if (m_file_data) {
delete m_file_data; m_file_data = 0;
}
}
nix_nar_t::type_regular_t::file_content_t::file_content_t(kaitai::kstream* p__io, nix_nar_t::type_regular_t* p__parent, nix_nar_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
f_nar_offset = false;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void nix_nar_t::type_regular_t::file_content_t::_read() {
m_len_contents = m__io->read_u8le();
n__unnamed1 = true;
if (nar_offset() < 0) {
n__unnamed1 = false;
m__unnamed1 = m__io->read_bytes(0);
}
m_contents = m__io->read_bytes(len_contents());
m_padding = m__io->read_bytes(kaitai::kstream::mod(8 - kaitai::kstream::mod(len_contents(), 8), 8));
{
std::string _ = m_padding;
if (!(((_.length() != 0) ? (kaitai::kstream::byte_array_max(_) == 0) : (true)))) {
throw kaitai::validation_expr_error<std::string>(m_padding, m__io, std::string("/types/type_regular/types/file_content/seq/3"));
}
}
}
nix_nar_t::type_regular_t::file_content_t::~file_content_t() {
_clean_up();
}
void nix_nar_t::type_regular_t::file_content_t::_clean_up() {
if (!n__unnamed1) {
}
}
int32_t nix_nar_t::type_regular_t::file_content_t::nar_offset() {
if (f_nar_offset)
return m_nar_offset;
f_nar_offset = true;
m_nar_offset = _io()->pos();
return m_nar_offset;
}
bool nix_nar_t::type_regular_t::is_executable() {
if (f_is_executable)
return m_is_executable;
f_is_executable = true;
m_is_executable = first_key()->body() == std::string("executable");
return m_is_executable;
}
nix_nar_t::type_symlink_t::type_symlink_t(kaitai::kstream* p__io, nix_nar_t::node_t* p__parent, nix_nar_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_target_key = 0;
m_target_val = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void nix_nar_t::type_symlink_t::_read() {
m_target_key = new padded_str_t(m__io, this, m__root);
{
padded_str_t* _ = m_target_key;
if (!(_->body() == std::string("target"))) {
throw kaitai::validation_expr_error<nix_nar_t::padded_str_t*>(m_target_key, m__io, std::string("/types/type_symlink/seq/0"));
}
}
m_target_val = new padded_bytes_t(m__io, this, m__root);
{
padded_bytes_t* _ = m_target_val;
if (!( ((_->body().length() != 0) && (_->body().length() <= 4095) && (kaitai::kstream::byte_array_min(_->body()) != 0)) )) {
throw kaitai::validation_expr_error<nix_nar_t::padded_bytes_t*>(m_target_val, m__io, std::string("/types/type_symlink/seq/1"));
}
}
}
nix_nar_t::type_symlink_t::~type_symlink_t() {
_clean_up();
}
void nix_nar_t::type_symlink_t::_clean_up() {
if (m_target_key) {
delete m_target_key; m_target_key = 0;
}
if (m_target_val) {
delete m_target_val; m_target_val = 0;
}
}