More work on extraction, especially for regular files

This commit is contained in:
Caleb Gardner
2026-05-08 06:06:33 -05:00
parent 5521b2ce6a
commit d76b164e45
8 changed files with 417 additions and 14 deletions
+25 -3
View File
@@ -8,7 +8,9 @@ const DirEntry = @import("directory.zig");
const ExtractionOptions = @import("options.zig");
const Inode = @import("inode.zig");
const DataExtractor = @import("util/data_extractor.zig");
const Decompressor = @import("util/decompressor.zig");
const MetadataReader = @import("util/metadata.zig");
const SharedCache = @import("util/shared_cache.zig");
const File = @This();
@@ -83,16 +85,36 @@ pub fn open(self: File, alloc: std.mem.Allocator, io: Io, filepath: []const u8)
}
pub fn extract(self: File, alloc: std.mem.Allocator, io: Io, filepath: []const u8, options: ExtractionOptions) !void {
var cache: SharedCache = try .init(alloc, 10); // TODO: calculate a good initial cache size.
defer cache.deinit();
var decomp = switch (self.archive.super.compression) {
.gzip => {},
.lzma => {},
.xz => {},
.zstd => {},
else => unreachable,
};
return self.extractReal(alloc, io, &cache, &decomp.interface, filepath, options);
}
fn extractReal(self: File, alloc: std.mem.Allocator, io: Io, cache: *SharedCache, decomp: *const Decompressor, filepath: []const u8, options: ExtractionOptions) !void {
_ = options;
switch (self.inode.hdr.inode_type) {
.file, .ext_file => {
var ext = try self.inode.dataExtractor(
self.archive.file,
cache,
decomp,
self.archive.super.block_size,
);
var atomic_file = try Io.Dir.cwd().createFileAtomic(io, filepath, .{});
defer atomic_file.deinit(io);
try ext.extract(alloc, io, atomic_file.file);
try atomic_file.link(io);
},
else => return error.TODO,
}
_ = alloc;
_ = options;
return error.TODO;
}
// Types