fhetch_transport/archive.h
Dead-simple TLV archive format used by the FHETCH transport.
One archive is one contiguous byte buffer:
magic(4) = "NBAR"
file_count(u32, little-endian)
repeat file_count times:
name_len(u32) name(bytes)
data_len(u64) data(bytes)Paths are stored verbatim relative to a base directory chosen by the writer. The reader is responsible for refusing any path that contains "..", starts with "/", or otherwise escapes its own extraction root.
This format exists because tar/zip would drag in a dependency and we only need to round-trip a flat tree of small-to-medium files between two trusted hosts on the same deployment.
Internal header. This file is part of the transport implementation and is not installed with the SDK.
Declarations
niobium::fhetch_transport::pack_directory
std::string pack_directory(const std::filesystem::path &root, const std::function<bool(const std::filesystem::path &rel)> &filter={})Pack every regular file under root whose relative path passes filter (default: accept all) into a single in-memory archive. The buffer is returned by value; caller is free to hand it straight to cpp-httplib.
Throws std::runtime_error on unreadable files or malformed input.
niobium::fhetch_transport::unpack_into
std::size_t unpack_into(const std::string &archive, const std::filesystem::path &dest)Reverse of pack_directory(). Writes each archived entry to dest / entry_name, creating parent directories as needed. Overwrites existing files without asking. Throws on malformed archives or on any path that would escape dest.
Returns the number of files extracted.
Streaming pack API (memory-bounded; used by the transport forwarder)
struct niobium::fhetch_transport::ArchiveEntry
struct niobium::fhetch_transport::ArchiveEntryFields
| Name | Declaration | Description |
|---|---|---|
abs | std::filesystem::path abs | |
rel | std::string rel | |
size | std::uint64_t size |
niobium::fhetch_transport::scan_directory
std::vector<ArchiveEntry> scan_directory(const std::filesystem::path &root, const std::function<bool(const std::filesystem::path &rel)> &filter={})First pass: enumerate the regular files under root that pass filter, validating each relative path. Mirrors pack_directory()'s scan.
niobium::fhetch_transport::archive_content_length
std::uint64_t archive_content_length(const std::vector<ArchiveEntry> &entries)Exact byte length of the archive stream_archive()/pack_directory() would produce for entries (magic + count + per-entry framing + file data).
niobium::fhetch_transport::stream_archive
bool stream_archive(const std::vector<ArchiveEntry> &entries, const std::function<bool(const char *data, std::size_t len)> &emit)Emit the archive for entries incrementally: emit(ptr, len) is called with successive byte spans (header, then per entry its framing followed by the file's bytes read in bounded chunks). Returns false as soon as emit returns false (e.g. the socket sink closed). Throws on unreadable/short files.
Streaming unpack (memory-bounded; used by the transport server)
class niobium::fhetch_transport::ArchiveUnpacker
class niobium::fhetch_transport::ArchiveUnpackerIncremental, chunk-boundary-agnostic counterpart to unpack_into(). feed() the archive bytes as they arrive (e.g. from an HTTP ContentReader); each file is written to disk on the fly, so the whole archive never sits in RAM. Any TLV field may be split across feed() calls. Consumes the same wire format as pack_directory()/stream_archive(), so it interoperates with either producer.
ArchiveUnpacker
explicit ArchiveUnpacker(std::filesystem::path dest)feed
void feed(const char *data, std::size_t len)Consume one span of archive bytes. Throws on malformed input, an unsafe path, or an I/O error (writing each file to dest / name).
finish
std::size_t finish()Verify the stream ended exactly on an entry boundary. Returns the number of files written. Throws if the archive was truncated mid-entry.
Something not looking right? Suggest a change on GitHub.