const std = @import("std"); const sys = @import("./sys.zig"); /// /// An entry block of an Oar archive file. /// /// Typically, following this block in memory is the file data it holds the meta-information for. /// pub const Entry = extern struct { signature: [3]u8 = signature_magic, revision: u8, name_length: u8 = 0, name_buffer: [255]u8 = std.mem.zeroes([255]u8), file_size: u64, padding: [244]u8 = std.mem.zeroes([244]u8), /// /// Returns `true` if `entry` correctly identifies itself as a valid Oar entry, otherwise /// `false`. /// pub fn isValid(entry: Entry) bool { return std.mem.eql(u8, &entry.signature, signature_magic[0 ..]); } /// /// Attempts to read an [Entry] from `file_access` at its current cursor position. /// /// Returns the read [Entry] value or `null` if the end of file is reached before completing the /// read. /// pub fn read(file_access: *sys.FileAccess) sys.FileAccess.Error!?Entry { var entry = std.mem.zeroes(Entry); const origin = try file_access.queryCursor(); if ((try file_access.read(std.mem.asBytes(&entry))) != @sizeOf(Entry)) { try file_access.seek(origin); return null; } return entry; } /// /// Magic identifier used to validate [Entry] data. /// const signature_magic = [3]u8{'o', 'a', 'r'}; };