Finished (?) Data extractor

This commit is contained in:
Caleb Gardner
2026-05-12 12:22:48 -05:00
parent ad05e5dff1
commit 2b0625e178
2 changed files with 14 additions and 10 deletions
+13 -9
View File
@@ -46,14 +46,18 @@ fn numBlocks(self: DataExtractor) usize {
return num; return num;
} }
pub fn extract(self: DataExtractor, alloc: std.mem.Allocator, io: Io, fil: Io.File) !void { /// Starts extracting the data using the given group to spawn async tasks.
_ = self; pub fn extractAsync(self: DataExtractor, alloc: std.mem.Allocator, io: Io, group: *Io.Group, fil: Io.File) void {
_ = alloc; var read_offset: u64 = self.start;
_ = io; for (0..self.blocks.len) |idx| {
_ = fil; group.async(io, blockThread, .{ self, alloc, io, fil, read_offset, idx });
read_offset += self.blocks[idx].size;
}
if (self.frag_entry != null)
group.async(io, fragThread, .{ self, alloc, io, fil });
} }
fn blockThread(self: DataExtractor, alloc: std.mem.Allocator, io: Io, fil: Io.File, read_offset: u64, offset: u64, idx: u32) !void { fn blockThread(self: DataExtractor, alloc: std.mem.Allocator, io: Io, fil: Io.File, read_offset: u64, idx: u32) !void {
const block = self.blocks[idx]; const block = self.blocks[idx];
const cur_block_size = if (idx == self.numBlocks() - 1) const cur_block_size = if (idx == self.numBlocks() - 1)
@@ -62,7 +66,7 @@ fn blockThread(self: DataExtractor, alloc: std.mem.Allocator, io: Io, fil: Io.Fi
self.block_size; self.block_size;
var wrt = fil.writer(io, &[0]u8{}); var wrt = fil.writer(io, &[0]u8{});
try wrt.seekTo(offset); try wrt.seekTo(self.block_size * idx);
defer wrt.flush() catch {}; defer wrt.flush() catch {};
if (block.size == 0) { if (block.size == 0) {
@@ -87,12 +91,12 @@ fn blockThread(self: DataExtractor, alloc: std.mem.Allocator, io: Io, fil: Io.Fi
try wrt.interface.writeAll(tmp.cache[0..cur_block_size]); try wrt.interface.writeAll(tmp.cache[0..cur_block_size]);
} }
} }
fn fragThread(self: DataExtractor, alloc: std.mem.Allocator, io: Io, fil: Io.File, offset: u64) !void { fn fragThread(self: DataExtractor, alloc: std.mem.Allocator, io: Io, fil: Io.File) !void {
const frag = self.frag_entry.?; const frag = self.frag_entry.?;
const cur_block_size = self.file_size % self.block_size; const cur_block_size = self.file_size % self.block_size;
var wrt = fil.writer(io, &[0]u8{}); var wrt = fil.writer(io, &[0]u8{});
try wrt.seekTo(offset); try wrt.seekTo(self.blocks.len * self.block_size);
defer wrt.flush() catch {}; defer wrt.flush() catch {};
var rdr = try self.fil.readerAt(io, frag.start, &[0]u8{}); var rdr = try self.fil.readerAt(io, frag.start, &[0]u8{});
+1 -1
View File
@@ -34,7 +34,7 @@ interface: Reader = .{
}, },
}, },
pub fn init(alloc: std.mem.Allocator, rdr: *Reader, decomp: *const Decompressor) This {] pub fn init(alloc: std.mem.Allocator, rdr: *Reader, decomp: *const Decompressor) This {
return .{ return .{
.alloc = alloc, .alloc = alloc,
.rdr = rdr, .rdr = rdr,