Started re-write (once again)

Main reason for this re-write is to be compatible with zig 0.16.0
This commit is contained in:
Caleb Gardner
2026-04-29 03:48:34 -05:00
parent 4b2b7021c7
commit b67d02074d
31 changed files with 238 additions and 2598 deletions
-14
View File
@@ -1,14 +0,0 @@
const std = @import("std");
const c = @import("../../c.zig").c;
const Decompressor = @import("../../decomp.zig");
const Self = @This();
interface: Decompressor = .{ .vtable = &.{ .stateless = stateless } },
fn stateless(_: std.mem.Allocator, in: []u8, out: []u8) Decompressor.Error!usize {
const res = c.LZ4_decompress_fast(in.ptr, out.ptr, @intCast(out.len));
if (res < 0) return Decompressor.Error.ReadFailed;
return @abs(res);
}
-127
View File
@@ -1,127 +0,0 @@
const std = @import("std");
const c = @import("../../c.zig").c;
const Decompressor = @import("../../decomp.zig");
const Self = @This();
alloc: std.mem.Allocator,
streams: std.AutoHashMap(std.Thread.Id, c.lzma_stream),
interface: Decompressor,
pub fn init(alloc: std.mem.Allocator) Self {
return .{
.alloc = alloc,
.streams = .init(alloc),
.interface = .{
.vtable = &.{
.decompress = decompress,
.stateless = stateless,
},
},
};
}
pub fn deinit(self: *Self) void {
self.streams.deinit();
}
fn decompress(decomp: *Decompressor, in: []u8, out: []u8) Decompressor.Error!usize {
var self: *Self = @fieldParentPtr("interface", decomp);
var strm = try self.getOrCreate();
strm.next_in = in.ptr;
strm.avail_in = in.len;
strm.next_out = out.ptr;
strm.avail_out = out.len;
var res = c.lzma_alone_decoder(strm, out.len * 2);
decodeResult(res) catch |err| return lzmaErrToDecompErr(err);
while (res == c.LZMA_OK)
res = c.lzma_code(strm, c.LZMA_RUN);
decodeResult(res) catch |err| return lzmaErrToDecompErr(err);
return strm.total_out;
}
fn stateless(alloc: std.mem.Allocator, in: []u8, out: []u8) Decompressor.Error!usize {
var strm: c.lzma_stream = .{
.allocator = &.{
.alloc = lzmaAlloc,
.free = lzmaFree,
.@"opaque" = @ptrCast(@constCast(&alloc)),
},
.next_in = in.ptr,
.avail_in = in.len,
.next_out = out.ptr,
.avail_out = out.len,
};
var res = c.lzma_alone_decoder(&strm, out.len * 2);
decodeResult(res) catch |err| return lzmaErrToDecompErr(err);
while (res == c.LZMA_OK)
res = c.lzma_code(&strm, c.LZMA_RUN);
decodeResult(res) catch |err| return lzmaErrToDecompErr(err);
return strm.total_out;
}
inline fn getOrCreate(self: *Self) !*c.lzma_stream {
const res = try self.streams.getOrPut(std.Thread.getCurrentId());
if (res.found_existing) return res.value_ptr;
res.value_ptr.* = .{ .allocator = &.{
.alloc = lzmaAlloc,
.free = lzmaFree,
.@"opaque" = @ptrCast(&self.alloc),
} };
return res.value_ptr;
}
inline fn decodeResult(res: usize) Error!void {
return switch (res) {
c.LZMA_OK, c.LZMA_STREAM_END => {},
c.LZMA_NO_CHECK => Error.NoCheck,
c.LZMA_UNSUPPORTED_CHECK => Error.UnsupportedCheck,
c.LZMA_GET_CHECK => Error.GetCheck,
c.LZMA_MEM_ERROR, c.LZMA_MEMLIMIT_ERROR => Error.OutOfMemory,
c.LZMA_FORMAT_ERROR => Error.Format,
c.LZMA_OPTIONS_ERROR => Error.Options,
c.LZMA_DATA_ERROR => Error.Data,
c.LZMA_BUF_ERROR => Error.Buffer,
c.LZMA_PROG_ERROR => Error.Program,
c.LZMA_SEEK_NEEDED => Error.SeekNeeded,
else => Error.Unknown,
};
}
inline fn lzmaErrToDecompErr(err: Error) Decompressor.Error {
return switch (err) {
Error.OutOfMemory => Decompressor.Error.OutOfMemory,
Error.NoCheck => Decompressor.Error.ReadFailed,
Error.UnsupportedCheck => Decompressor.Error.ReadFailed,
Error.GetCheck => Decompressor.Error.ReadFailed,
Error.Format => Decompressor.Error.ReadFailed,
Error.Options => Decompressor.Error.ReadFailed,
Error.Data => Decompressor.Error.ReadFailed,
Error.Buffer => Decompressor.Error.WriteFailed,
Error.Program => Decompressor.Error.ReadFailed,
Error.SeekNeeded => Decompressor.Error.ReadFailed,
else => Decompressor.Error.ReadFailed,
};
}
fn lzmaAlloc(ptr: ?*anyopaque, size: usize, _: usize) callconv(.c) ?*anyopaque {
var alloc: *std.mem.Allocator = @ptrCast(@alignCast(@constCast(ptr)));
return alloc.rawAlloc(size, .@"1", 0);
}
fn lzmaFree(ptr: ?*anyopaque, mem_ptr: ?*anyopaque) callconv(.c) void {
var alloc: *std.mem.Allocator = @ptrCast(@alignCast(@constCast(ptr)));
alloc.rawFree(@ptrCast(mem_ptr), .@"1", 0);
}
const Error = error{
OutOfMemory,
NoCheck,
UnsupportedCheck,
GetCheck,
Format,
Options,
Data,
Buffer,
Program,
SeekNeeded,
Unknown,
};
-67
View File
@@ -1,67 +0,0 @@
const std = @import("std");
const c = @import("../../c.zig").c;
const Decompressor = @import("../../decomp.zig");
const Self = @This();
interface: Decompressor = .{ .vtable = &.{ .stateless = stateless } },
fn stateless(_: std.mem.Allocator, in: []u8, out: []u8) Decompressor.Error!usize {
var out_len: usize = out.len;
const res = c.lzo1x_decompress(in.ptr, in.len, out.ptr, &out_len, null);
decodeError(res) catch |err| return lzoErrToDecompErr(err);
return out_len;
}
inline fn decodeError(res: c_int) Error!void {
return switch (res) {
c.LZO_E_OK => {},
c.LZO_E_EOF_NOT_FOUND => Error.EofNotFound,
c.LZO_E_INPUT_NOT_CONSUMED => Error.InputNotConsumed,
c.LZO_E_INPUT_OVERRUN => Error.InputOverrun,
c.LZO_E_INTERNAL_ERROR => Error.InternalError,
c.LZO_E_INVALID_ALIGNMENT => Error.InvalidAlignment,
c.LZO_E_INVALID_ARGUMENT => Error.InvalidArgument,
c.LZO_E_LOOKBEHIND_OVERRUN => Error.LookbehindOverrun,
c.LZO_E_NOT_COMPRESSIBLE => Error.NotCompressible,
c.LZO_E_NOT_YET_IMPLEMENTED => Error.NotYetImplemented,
c.LZO_E_OUTPUT_NOT_CONSUMED => Error.OutputNotConsumed,
c.LZO_E_OUTPUT_OVERRUN => Error.OutputOverrun,
c.LZO_E_OUT_OF_MEMORY => Error.OutOfMemory,
else => Error.Unknown,
};
}
inline fn lzoErrToDecompErr(err: Error) Decompressor.Error {
return switch (err) {
Error.EofNotFound => Decompressor.Error.ReadFailed,
Error.InputNotConsumed => Decompressor.Error.ReadFailed,
Error.InputOverrun => Decompressor.Error.ReadFailed,
Error.InternalError => Decompressor.Error.ReadFailed,
Error.InvalidAlignment => Decompressor.Error.ReadFailed,
Error.InvalidArgument => Decompressor.Error.ReadFailed,
Error.LookbehindOverrun => Decompressor.Error.ReadFailed,
Error.NotCompressible => Decompressor.Error.ReadFailed,
Error.NotYetImplemented => Decompressor.Error.ReadFailed,
Error.OutputNotConsumed => Decompressor.Error.WriteFailed,
Error.OutputOverrun => Decompressor.Error.WriteFailed,
Error.OutOfMemory => Decompressor.Error.OutOfMemory,
else => Decompressor.Error.ReadFailed,
};
}
const Error = error{
EofNotFound,
InputNotConsumed,
InputOverrun,
InternalError,
InvalidAlignment,
InvalidArgument,
LookbehindOverrun,
NotCompressible,
NotYetImplemented,
OutputNotConsumed,
OutputOverrun,
OutOfMemory,
Unknown,
};
-127
View File
@@ -1,127 +0,0 @@
const std = @import("std");
const c = @import("../../c.zig").c;
const Decompressor = @import("../../decomp.zig");
const Self = @This();
alloc: std.mem.Allocator,
streams: std.AutoHashMap(std.Thread.Id, c.lzma_stream),
interface: Decompressor,
pub fn init(alloc: std.mem.Allocator) Self {
return .{
.alloc = alloc,
.streams = .init(alloc),
.interface = .{
.vtable = &.{
.decompress = decompress,
.stateless = stateless,
},
},
};
}
pub fn deinit(self: *Self) void {
self.streams.deinit();
}
fn decompress(decomp: *Decompressor, in: []u8, out: []u8) Decompressor.Error!usize {
var self: *Self = @fieldParentPtr("interface", decomp);
var strm = try self.getOrCreate();
strm.next_in = in.ptr;
strm.avail_in = in.len;
strm.next_out = out.ptr;
strm.avail_out = out.len;
var res = c.lzma_stream_decoder(strm, out.len * 2, 0);
decodeResult(res) catch |err| return lzmaErrToDecompErr(err);
while (res == c.LZMA_OK)
res = c.lzma_code(strm, c.LZMA_RUN);
decodeResult(res) catch |err| return lzmaErrToDecompErr(err);
return strm.total_out;
}
fn stateless(alloc: std.mem.Allocator, in: []u8, out: []u8) Decompressor.Error!usize {
var strm: c.lzma_stream = .{
.allocator = &.{
.alloc = lzmaAlloc,
.free = lzmaFree,
.@"opaque" = @ptrCast(@constCast(&alloc)),
},
.next_in = in.ptr,
.avail_in = in.len,
.next_out = out.ptr,
.avail_out = out.len,
};
var res = c.lzma_stream_decoder(&strm, out.len * 2, 0);
decodeResult(res) catch |err| return lzmaErrToDecompErr(err);
while (res == c.LZMA_OK)
res = c.lzma_code(&strm, c.LZMA_RUN);
decodeResult(res) catch |err| return lzmaErrToDecompErr(err);
return strm.total_out;
}
inline fn getOrCreate(self: *Self) !*c.lzma_stream {
const res = try self.streams.getOrPut(std.Thread.getCurrentId());
if (res.found_existing) return res.value_ptr;
res.value_ptr.* = .{ .allocator = &.{
.alloc = lzmaAlloc,
.free = lzmaFree,
.@"opaque" = @ptrCast(&self.alloc),
} };
return res.value_ptr;
}
inline fn decodeResult(res: usize) Error!void {
return switch (res) {
c.LZMA_OK, c.LZMA_STREAM_END => {},
c.LZMA_NO_CHECK => Error.NoCheck,
c.LZMA_UNSUPPORTED_CHECK => Error.UnsupportedCheck,
c.LZMA_GET_CHECK => Error.GetCheck,
c.LZMA_MEM_ERROR, c.LZMA_MEMLIMIT_ERROR => Error.OutOfMemory,
c.LZMA_FORMAT_ERROR => Error.Format,
c.LZMA_OPTIONS_ERROR => Error.Options,
c.LZMA_DATA_ERROR => Error.Data,
c.LZMA_BUF_ERROR => Error.Buffer,
c.LZMA_PROG_ERROR => Error.Program,
c.LZMA_SEEK_NEEDED => Error.SeekNeeded,
else => Error.Unknown,
};
}
inline fn lzmaErrToDecompErr(err: Error) Decompressor.Error {
return switch (err) {
Error.OutOfMemory => Decompressor.Error.OutOfMemory,
Error.NoCheck => Decompressor.Error.ReadFailed,
Error.UnsupportedCheck => Decompressor.Error.ReadFailed,
Error.GetCheck => Decompressor.Error.ReadFailed,
Error.Format => Decompressor.Error.ReadFailed,
Error.Options => Decompressor.Error.ReadFailed,
Error.Data => Decompressor.Error.ReadFailed,
Error.Buffer => Decompressor.Error.WriteFailed,
Error.Program => Decompressor.Error.ReadFailed,
Error.SeekNeeded => Decompressor.Error.ReadFailed,
else => Decompressor.Error.ReadFailed,
};
}
fn lzmaAlloc(ptr: ?*anyopaque, size: usize, _: usize) callconv(.c) ?*anyopaque {
var alloc: *std.mem.Allocator = @ptrCast(@alignCast(@constCast(ptr)));
return alloc.rawAlloc(size, .@"1", 0);
}
fn lzmaFree(ptr: ?*anyopaque, mem_ptr: ?*anyopaque) callconv(.c) void {
var alloc: *std.mem.Allocator = @ptrCast(@alignCast(@constCast(ptr)));
alloc.rawFree(@ptrCast(mem_ptr), .@"1", 0);
}
const Error = error{
OutOfMemory,
NoCheck,
UnsupportedCheck,
GetCheck,
Format,
Options,
Data,
Buffer,
Program,
SeekNeeded,
Unknown,
};
-112
View File
@@ -1,112 +0,0 @@
const std = @import("std");
const c = @import("../../c.zig").c;
const Decompressor = @import("../../decomp.zig");
const Self = @This();
alloc: std.mem.Allocator,
streams: std.AutoHashMap(std.Thread.Id, c.zng_stream),
interface: Decompressor,
pub fn init(alloc: std.mem.Allocator) Self {
return .{
.alloc = alloc,
.streams = .init(alloc),
.interface = .{
.vtable = &.{
.decompress = decompress,
.stateless = stateless,
},
},
};
}
pub fn deinit(self: *Self) void {
self.streams.deinit();
}
fn decompress(decomp: *Decompressor, in: []u8, out: []u8) Decompressor.Error!usize {
const self: *Self = @fieldParentPtr("interface", decomp);
var strm = try self.getOrCreate();
strm.next_in = in.ptr;
strm.avail_in = @truncate(in.len);
strm.next_out = out.ptr;
strm.total_out = out.len;
var res = c.zng_inflateReset(strm);
decodeError(res) catch |err| return zlibErrToDecompErr(err);
res = c.zng_inflate(strm, c.Z_FULL_FLUSH);
decodeError(res) catch |err| return zlibErrToDecompErr(err);
return strm.total_out;
}
fn stateless(alloc: std.mem.Allocator, in: []u8, out: []u8) Decompressor.Error!usize {
var strm: c.zng_stream = .{
.zalloc = zalloc,
.zfree = zfree,
.@"opaque" = @constCast(&alloc),
.next_in = in.ptr,
.avail_in = @truncate(in.len),
.next_out = out.ptr,
.total_out = out.len,
};
var res = c.zng_inflateInit(&strm);
decodeError(res) catch |err| return zlibErrToDecompErr(err);
res = c.zng_inflate(&strm, c.Z_FULL_FLUSH);
decodeError(res) catch |err| return zlibErrToDecompErr(err);
return strm.total_out;
}
fn getOrCreate(self: *Self) !*c.zng_stream {
const res = try self.streams.getOrPut(std.Thread.getCurrentId());
if (res.found_existing) return res.value_ptr;
res.value_ptr.* = .{
.zalloc = zalloc,
.zfree = zfree,
.@"opaque" = &self.alloc,
};
return res.value_ptr;
}
fn zalloc(ptr: ?*anyopaque, size: c_uint, len: c_uint) callconv(.c) ?*anyopaque {
var alloc: *std.mem.Allocator = @ptrCast(@alignCast(@constCast(ptr)));
return alloc.rawAlloc(size * len, .@"1", 0);
}
fn zfree(ptr: ?*anyopaque, mem_ptr: ?*anyopaque) callconv(.c) void {
var alloc: *std.mem.Allocator = @ptrCast(@alignCast(@constCast(ptr)));
alloc.rawFree(@ptrCast(mem_ptr), .@"1", 0);
}
inline fn decodeError(res: i32) Error!void {
if (res >= 0) return;
return switch (res) {
c.Z_STREAM_ERROR => Error.Stream,
c.Z_DATA_ERROR => Error.Data,
c.Z_MEM_ERROR => Error.OutOfMemory,
c.Z_BUF_ERROR => Error.Buffer,
c.Z_VERSION_ERROR => Error.Version,
else => Error.Misc,
};
}
inline fn zlibErrToDecompErr(err: Error) Decompressor.Error {
return switch (err) {
Error.OutOfMemory => Decompressor.Error.OutOfMemory,
Error.Misc => Decompressor.Error.ReadFailed,
Error.Stream => Decompressor.Error.ReadFailed,
Error.Data => Decompressor.Error.ReadFailed,
Error.Buffer => Decompressor.Error.WriteFailed,
Error.Version => Decompressor.Error.ReadFailed,
};
}
const Error = error{
OutOfMemory,
Misc,
Stream,
Data,
Buffer,
Version,
};
-165
View File
@@ -1,165 +0,0 @@
const std = @import("std");
const c = @import("../../c.zig").c;
const Decompressor = @import("../../decomp.zig");
const Self = @This();
alloc: std.mem.Allocator,
ctx: std.AutoHashMap(std.Thread.Id, ?*c.ZSTD_DCtx),
interface: Decompressor,
pub fn init(alloc: std.mem.Allocator) Self {
return .{
.alloc = alloc,
.ctx = .init(alloc),
.interface = .{
.vtable = &.{
.decompress = decompress,
.stateless = stateless,
},
},
};
}
pub fn deinit(self: *Self) void {
self.ctx.deinit();
}
fn decompress(decomp: *Decompressor, in: []u8, out: []u8) Decompressor.Error!usize {
var self: *Self = @fieldParentPtr("interface", decomp);
const ctx = try self.getOrCreate();
const res = c.ZSTD_decompressDCtx(ctx, out.ptr, out.len, in.ptr, in.len);
decodeError(res) catch |err| return zstdErrToDecompErr(err);
return res;
}
fn stateless(_: std.mem.Allocator, in: []u8, out: []u8) Decompressor.Error!usize {
const res = c.ZSTD_decompress(out.ptr, out.len, in.ptr, in.len);
decodeError(res) catch |err| return zstdErrToDecompErr(err);
return res;
}
inline fn getOrCreate(self: *Self) !?*c.ZSTD_DCtx {
const res = try self.ctx.getOrPut(std.Thread.getCurrentId());
if (res.found_existing) return res.value_ptr.*;
res.value_ptr.* = c.ZSTD_createDCtx();
return res.value_ptr.*;
}
inline fn decodeError(res: usize) Error!void {
if (c.ZSTD_isError(res) == 0) return;
return switch (c.ZSTD_getErrorCode(res)) {
c.ZSTD_error_prefix_unknown => Error.PrefixUnknown,
c.ZSTD_error_version_unsupported => Error.VersionUnsupported,
c.ZSTD_error_frameParameter_unsupported => Error.FrameParameterUnsupported,
c.ZSTD_error_frameParameter_windowTooLarge => Error.FrameParameterWindowTooLarge,
c.ZSTD_error_corruption_detected => Error.CorruptionDetected,
c.ZSTD_error_checksum_wrong => Error.ChecksumWrong,
c.ZSTD_error_literals_headerWrong => Error.LiteralsHeaderWrong,
c.ZSTD_error_dictionary_corrupted => Error.DictionaryCorrupted,
c.ZSTD_error_dictionary_wrong => Error.DictionaryWrong,
c.ZSTD_error_dictionaryCreation_failed => Error.DictionaryCreationFailed,
c.ZSTD_error_parameter_unsupported => Error.ParameterUnsupported,
c.ZSTD_error_parameter_combination_unsupported => Error.ParameterCombinationUnsupported,
c.ZSTD_error_parameter_outOfBound => Error.ParameterOutOfBound,
c.ZSTD_error_tableLog_tooLarge => Error.TableLogTooLarge,
c.ZSTD_error_maxSymbolValue_tooLarge => Error.MaxSymbolValueTooLarge,
c.ZSTD_error_maxSymbolValue_tooSmall => Error.MaxSymbolValueTooSmall,
c.ZSTD_error_cannotProduce_uncompressedBlock => Error.CannotProduceUncompressedBlock,
c.ZSTD_error_stabilityCondition_notRespected => Error.StabilityConditionNotRespected,
c.ZSTD_error_stage_wrong => Error.StageWrong,
c.ZSTD_error_init_missing => Error.InitMissing,
c.ZSTD_error_memory_allocation => Error.MemoryAllocation,
c.ZSTD_error_workSpace_tooSmall => Error.WorkSpaceTooSmall,
c.ZSTD_error_dstSize_tooSmall => Error.DstSizeTooSmall,
c.ZSTD_error_srcSize_wrong => Error.SrcSizeWrong,
c.ZSTD_error_dstBuffer_null => Error.DstBufferNull,
c.ZSTD_error_noForwardProgress_destFull => Error.NoForwardProgressDestFull,
c.ZSTD_error_noForwardProgress_inputEmpty => Error.NoForwardProgressInputEmpty,
c.ZSTD_error_frameIndex_tooLarge => Error.FrameIndexTooLarge,
c.ZSTD_error_seekableIO => Error.SeekableIo,
c.ZSTD_error_dstBuffer_wrong => Error.DstBufferWrong,
c.ZSTD_error_srcBuffer_wrong => Error.SrcBufferWrong,
c.ZSTD_error_sequenceProducer_failed => Error.SequenceProducerFailed,
c.ZSTD_error_externalSequences_invalid => Error.ExternalSequencesInvalid,
else => Error.Generic,
};
}
inline fn zstdErrToDecompErr(err: Error) Decompressor.Error {
return switch (err) {
Error.OutOfMemory => Decompressor.Error.OutOfMemory,
Error.Generic => Decompressor.Error.ReadFailed,
Error.PrefixUnknown => Decompressor.Error.ReadFailed,
Error.VersionUnsupported => Decompressor.Error.ReadFailed,
Error.FrameParameterUnsupported => Decompressor.Error.ReadFailed,
Error.FrameParameterWindowTooLarge => Decompressor.Error.ReadFailed,
Error.CorruptionDetected => Decompressor.Error.ReadFailed,
Error.ChecksumWrong => Decompressor.Error.ReadFailed,
Error.LiteralsHeaderWrong => Decompressor.Error.ReadFailed,
Error.DictionaryCorrupted => Decompressor.Error.ReadFailed,
Error.DictionaryWrong => Decompressor.Error.ReadFailed,
Error.DictionaryCreationFailed => Decompressor.Error.ReadFailed,
Error.ParameterUnsupported => Decompressor.Error.ReadFailed,
Error.ParameterCombinationUnsupported => Decompressor.Error.ReadFailed,
Error.ParameterOutOfBound => Decompressor.Error.ReadFailed,
Error.TableLogTooLarge => Decompressor.Error.ReadFailed,
Error.MaxSymbolValueTooLarge => Decompressor.Error.ReadFailed,
Error.MaxSymbolValueTooSmall => Decompressor.Error.ReadFailed,
Error.CannotProduceUncompressedBlock => Decompressor.Error.ReadFailed,
Error.StabilityConditionNotRespected => Decompressor.Error.ReadFailed,
Error.StageWrong => Decompressor.Error.ReadFailed,
Error.InitMissing => Decompressor.Error.ReadFailed,
Error.MemoryAllocation => Decompressor.Error.OutOfMemory,
Error.WorkSpaceTooSmall => Decompressor.Error.WriteFailed,
Error.DstSizeTooSmall => Decompressor.Error.WriteFailed,
Error.SrcSizeWrong => Decompressor.Error.ReadFailed,
Error.DstBufferNull => Decompressor.Error.WriteFailed,
Error.NoForwardProgressDestFull => Decompressor.Error.WriteFailed,
Error.NoForwardProgressInputEmpty => Decompressor.Error.ReadFailed,
Error.FrameIndexTooLarge => Decompressor.Error.ReadFailed,
Error.SeekableIo => Decompressor.Error.ReadFailed,
Error.DstBufferWrong => Decompressor.Error.WriteFailed,
Error.SrcBufferWrong => Decompressor.Error.ReadFailed,
Error.SequenceProducerFailed => Decompressor.Error.ReadFailed,
Error.ExternalSequencesInvalid => Decompressor.Error.ReadFailed,
};
}
const Error = error{
OutOfMemory,
Generic,
PrefixUnknown,
VersionUnsupported,
FrameParameterUnsupported,
FrameParameterWindowTooLarge,
CorruptionDetected,
ChecksumWrong,
LiteralsHeaderWrong,
DictionaryCorrupted,
DictionaryWrong,
DictionaryCreationFailed,
ParameterUnsupported,
ParameterCombinationUnsupported,
ParameterOutOfBound,
TableLogTooLarge,
MaxSymbolValueTooLarge,
MaxSymbolValueTooSmall,
CannotProduceUncompressedBlock,
StabilityConditionNotRespected,
StageWrong,
InitMissing,
MemoryAllocation,
WorkSpaceTooSmall,
DstSizeTooSmall,
SrcSizeWrong,
DstBufferNull,
NoForwardProgressDestFull,
NoForwardProgressInputEmpty,
FrameIndexTooLarge,
SeekableIo,
DstBufferWrong,
SrcBufferWrong,
SequenceProducerFailed,
ExternalSequencesInvalid,
};
-43
View File
@@ -1,43 +0,0 @@
const config = @import("config");
const Decompressor = @import("../decomp.zig");
const cLz4 = @import("c/lz4.zig");
const cLzma = @import("c/lzma.zig");
const cLzo = @import("c/lzo.zig");
const cXz = @import("c/xz.zig");
const cZlib = @import("c/zlib.zig");
const cZstd = @import("c/zstd.zig");
const zigLzma = @import("zig/lzma.zig");
const zigXz = @import("zig/xz.zig");
const zigZlib = @import("zig/zstd.zig");
const zigZstd = @import("zig/zstd.zig");
pub const Decomp = union(enum) {
gzip: if (config.use_zig_decomp) zigZlib else cZlib,
lzma: if (config.use_zig_decomp) zigLzma else cLzma,
lzo: if (config.use_zig_decomp) void else cLzo,
xz: if (config.use_zig_decomp) zigXz else cXz,
lz4: if (config.use_zig_decomp) void else cLz4,
zstd: if (config.use_zig_decomp) zigZstd else cZstd,
pub fn deinit(self: *Decomp) void {
switch (self) {
.gzip => self.gzip.deinit(),
.lzma => self.lzma.deinit(),
.xz => self.xz.deinit(),
.zstd => self.zstd.deinit(),
else => {},
}
}
pub fn decompressor(self: *Decomp) *Decompressor {
return switch (self) {
.gzip => &self.gzip.interface,
.lzma => &self.lzma.interface,
.lzo => &self.lzo.interface,
.xz => &self.xz.interface,
.lz4 => &self.lz4.interface,
.zstd => &self.zstd.interface,
};
}
};
-19
View File
@@ -1,19 +0,0 @@
const std = @import("std");
const lzma = std.compress.lzma;
const Reader = std.Io.Reader;
const Decompressor = @import("../../decomp.zig");
const Self = @This();
interface: Decompressor = .{ .vtable = &.{ .stateless = stateless } },
fn stateless(alloc: std.mem.Allocator, in: []u8, out: []u8) Decompressor.Error!usize {
var rdr: Reader = .fixed(in);
var decomp = try lzma.decompress(alloc, rdr.adaptToOldInterface());
defer decomp.deinit();
return decomp.read(out) catch |err| switch (err) {
error.CorruptInput, error.EndOfStream, error.Overflow => return Decompressor.Error.ReadFailed,
else => return err,
};
}
-25
View File
@@ -1,25 +0,0 @@
const std = @import("std");
const xz = std.compress.xz;
const Reader = std.Io.Reader;
const Decompressor = @import("../../decomp.zig");
const Self = @This();
interface: Decompressor = .{ .vtable = &.{ .stateless = stateless } },
fn stateless(alloc: std.mem.Allocator, in: []u8, out: []u8) Decompressor.Error!usize {
var rdr: Reader = .fixed(in);
var decomp = try xz.decompress(alloc, rdr.adaptToOldInterface());
defer decomp.deinit();
return decomp.read(out) catch |err| switch (err) {
error.CorruptInput,
error.EndOfStream,
error.EndOfStreamWithNoError,
error.WrongChecksum,
error.Unsupported,
error.Overflow,
=> Decompressor.Error.ReadFailed,
else => return err,
};
}
-18
View File
@@ -1,18 +0,0 @@
const std = @import("std");
const Reader = std.Io.Reader;
const flate = std.compress.flate;
const Decompressor = @import("../../decomp.zig");
const Self = @This();
interface: Decompressor = .{ .vtable = &.{ .stateless = stateless } },
fn stateless(alloc: std.mem.Allocator, in: []u8, out: []u8) Decompressor.Error!usize {
const buf = try alloc.alloc(u8, out.len);
defer alloc.free(buf);
var rdr: Reader = .fixed(in);
var decomp = flate.Decompress.init(&rdr, .zlib, buf);
return decomp.reader.readSliceShort(out);
}
-18
View File
@@ -1,18 +0,0 @@
const std = @import("std");
const Reader = std.Io.Reader;
const zstd = std.compress.zstd;
const Decompressor = @import("../../decomp.zig");
const Self = @This();
interface: Decompressor = .{ .vtable = &.{ .stateless = stateless } },
fn stateless(alloc: std.mem.Allocator, in: []u8, out: []u8) Decompressor.Error!usize {
const buf = try alloc.alloc(u8, out.len * 2);
defer alloc.free(buf);
var rdr: Reader = .fixed(in);
var decomp = zstd.Decompress.init(&rdr, buf, .{ .window_len = @min(out.len, zstd.default_window_len) });
return decomp.reader.readSliceShort(out);
}