-
Notifications
You must be signed in to change notification settings - Fork 72
Description
I'm dealing with an old file format where sqlite is used to fetch BLOBs of zlib-compressed data. As far as I can tell, zig-sqlite has only one way I can do that:
const file_query: []const u8 = "SELECT DATA FROM cache WHERE KEY = ?";
const row_opt = stmt.oneAlloc([]const u8, allocator, .{}, .{ .KEY = entry.archive_id }) catch |err| {
// ...
};
const row = row_opt.?;
defer allocator.free(row);(error-checking trimmed for brevity)
This works fine, but it's a shame to have to use an allocator, as it's the only thing in my entire library that would require one.
I read some comments in your repo which suggest that the reason it's like this is because there would be no other way to communicate the length of the data to the caller, and while I can understand that being a problem in most cases (string), in my case I will be able to find the length of the data for myself by reading the data. The zlib decompressor will inherently know the difference between reaching the end of the data and stopping unexpectedly because that's an inherent part of the compression format.
So is there a way I could do this without an allocator? I'm envisioning a function which takes T: type, and the function passes a GenericReader interface to T.init and returns the struct that it creates.
Thanks in advance for any guidance, I'm new to zig FYI, but enjoying it so far.