A bit more work on metadata reader
This commit is contained in:
+35
-1
@@ -1,11 +1,45 @@
|
||||
const std = @import("std");
|
||||
const io = std.io;
|
||||
|
||||
const MetadataHeader = packed struct {
|
||||
compressed: bool,
|
||||
not_compressed: bool,
|
||||
size: u15,
|
||||
};
|
||||
|
||||
const MetadataReader = struct {
|
||||
rdr: std.io.AnyReader,
|
||||
alloc: std.heap.Allocator,
|
||||
curBlock: []const u8,
|
||||
curOffset: u16,
|
||||
|
||||
pub fn init(rdr: io.AnyReader, alloc: std.heap.Allocator) !MetadataReader {
|
||||
const out = .{
|
||||
.rdr = rdr,
|
||||
.alloc = alloc,
|
||||
.curBlock = undefined,
|
||||
.curOffset = 0,
|
||||
};
|
||||
try out.readNextBlock();
|
||||
return out;
|
||||
}
|
||||
pub fn any(self: MetadataReader) !io.AnyReader {
|
||||
return .{
|
||||
.context = @ptrCast(&self),
|
||||
.readFn = typeErasedReadFn,
|
||||
};
|
||||
}
|
||||
|
||||
fn readNextBlock(self: MetadataReader) !void {
|
||||
if (self.curBlock != undefined) {
|
||||
self.alloc.free(self.curBlock);
|
||||
}
|
||||
self.curOffset = 0;
|
||||
const hdr = try self.rdr.readStruct(MetadataHeader);
|
||||
const buf = try self.alloc.alloc(u8, hdr.size);
|
||||
if (hdr.not_compressed) {
|
||||
self.curBlock = buf;
|
||||
} else {
|
||||
//TODO: decompress
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -23,7 +23,6 @@ pub fn newReader(filename: []const u8) !Reader {
|
||||
errdefer alloc.deinit();
|
||||
const super = try file.reader().readStruct(Superblock);
|
||||
try super.valid();
|
||||
|
||||
return Reader{
|
||||
.super = super,
|
||||
.rdr = file,
|
||||
|
||||
Reference in New Issue
Block a user