Moved to File.MemoryMap instead of direct file I/O

This commit is contained in:
Caleb Gardner
2026-05-22 12:49:07 -05:00
parent 8186c3fe9a
commit 0df14b8adc
13 changed files with 126 additions and 427 deletions
+16 -14
View File
@@ -24,7 +24,7 @@ pub fn init(io: Io, file: std.Io.File, offset: u64) !Archive {
var super: Superblock = undefined;
try rdr.interface.readSliceEndian(Superblock, @ptrCast(&super), .little);
return .{
.file = .init(file, offset),
.file = try .init(io, file, super.size, offset),
.super = super,
.stateless_decomp = try Decomp.StatelessDecomp(super.compression),
@@ -53,19 +53,6 @@ pub fn open(self: Archive, alloc: std.mem.Allocator, io: Io, filepath: []const u
defer root_file.deinit();
return root_file.open(alloc, io, filepath);
}
/// Extract the entire archive contents to the given directory.
pub fn extract(self: Archive, alloc: std.mem.Allocator, io: Io, extract_dir: []const u8, options: ExtractionOptions) !void {
const root_inode = try Utils.inodeFromRef(
alloc,
io,
self.file,
self.stateless_decomp,
self.super.inode_start,
self.super.block_size,
self.super.root_ref,
);
return root_inode.extract(alloc, io, self.file, self.super, extract_dir, options);
}
/// Returns the inode with the given inode number.
/// Requires that the archive is exportable (has an export lookup table).
@@ -163,3 +150,18 @@ pub const Superblock = extern struct {
return SuperblockError.InvalidBlockLog;
}
};
// Extraction
/// Extract the entire archive contents to the given directory.
pub fn extract(self: Archive, alloc: std.mem.Allocator, io: Io, extract_dir: []const u8, options: ExtractionOptions) !void {
const root_inode = try Utils.inodeFromRef(
alloc,
self.file,
self.stateless_decomp,
self.super.inode_start,
self.super.block_size,
self.super.root_ref,
);
return root_inode.extract(alloc, io, self.file, self.super, extract_dir, options);
}