Environment:
OS: Manjaro Linux
Zig: 0.13.0
I’m trying to decompress an LZMA-compressed binary data file using Zig’s std.compress.lzma
. Here’s the code I’m working with:
const std = @import("std");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
// Open compressed file for reading
const file_path = "./01h_ticks";
var file = try std.fs.cwd().openFile(file_path, .{});
defer file.close();
// Read compressed file into memory
const compressed_data = try allocator.alloc(u8, 20_000);
defer allocator.free(compressed_data);
_ = try file.readAll(compressed_data);
// Wrap the compressed data in a FixedBufferStream
var compressed_stream = std.io.fixedBufferStream(compressed_data);
const compressed_reader = compressed_stream.reader();
// Create a decompression stream
var decompress_stream = try std.compress.lzma.decompress(allocator, compressed_reader);
defer decompress_stream.deinit();
const decompress_stream_reader = decompress_stream.reader();
// Allocate a buffer for decompressed data
var temp_buffer: []u8 = try allocator.alloc(u8, 20_000);
defer allocator.free(temp_buffer);
// Read decompressed data
_ = try decompress_stream_reader.read(temp_buffer[0..]);
}
However, I run into the following runtime error when calling read()
on the decompress_stream_reader
:
thread 1436544 panic: @memcpy arguments alias
/usr/lib/zig/std/compress/lzma.zig:80:53: 0x103cc58 in read (main)
@memcpy(input[0 .. input.len - n], input[n..]);
^
/usr/lib/zig/std/io.zig:94:26: 0x103b95b in main (main)
return readFn(self.context, buffer);
^
/usr/lib/zig/std/start.zig:524:37: 0x1038f25 in posixCallMainAndExit (main)
const result = root.main() catch |err| {
^
/usr/lib/zig/std/start.zig:266:5: 0x1038a41 in _start (main)
asm volatile (switch (native_arch) {
^
???:?:?: 0x0 in ??? (???)
[1] 1436544 IOT instruction (core dumped)
Does anyone have experience working with std.compress.lzma
and know what might be causing this? Any help would be greatly appreciated.
Thanks in advance.