-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Further simplify compression code, add libz support
- Loading branch information
Showing
8 changed files
with
187 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
.{ | ||
.name = "squashfuse-zig", | ||
.version = "0.3.1", | ||
.version = "0.3.2", | ||
|
||
.paths = [][]const u8{ | ||
"build.zig", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const std = @import("std"); | ||
const compression = @import("../compression.zig"); | ||
const DecompressError = compression.DecompressError; | ||
|
||
pub const required_symbols = struct { | ||
pub var uncompress: *const fn ( | ||
[*]u8, | ||
*c_ulong, | ||
[*]const u8, | ||
c_ulong, | ||
) callconv(.C) c_int = undefined; | ||
}; | ||
|
||
pub fn decode( | ||
allocator: std.mem.Allocator, | ||
in: []const u8, | ||
out: []u8, | ||
) DecompressError!usize { | ||
_ = allocator; | ||
|
||
var written: c_ulong = @intCast(out.len); | ||
|
||
const err = required_symbols.uncompress( | ||
out.ptr, | ||
&written, | ||
in.ptr, | ||
in.len, | ||
); | ||
|
||
// TODO: audit these and ensure they're correct | ||
if (err < 0) return switch (err) { | ||
// Z_STREAM_ERROR | ||
-2 => DecompressError.ShortOutput, | ||
|
||
// Z_DATA_ERROR | ||
-3 => DecompressError.CorruptInput, | ||
|
||
// Z_MEM_ERROR | ||
-4 => DecompressError.OutOfMemory, | ||
|
||
// Z_BUF_ERROR | ||
-5 => DecompressError.NoSpaceLeft, | ||
|
||
// Z_ERRNO, Z_VERSION_ERROR | ||
-1, -6 => DecompressError.Error, | ||
|
||
else => DecompressError.Error, | ||
}; | ||
|
||
return written; | ||
} |
Oops, something went wrong.