Skip to content

Commit ad2becd

Browse files
committed
package fetching: support .tar.zst archives
1 parent e44152e commit ad2becd

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Package/Fetch.zig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,12 +752,14 @@ const FileType = enum {
752752
tar,
753753
@"tar.gz",
754754
@"tar.xz",
755+
@"tar.zst",
755756
git_pack,
756757

757758
fn fromPath(file_path: []const u8) ?FileType {
758759
if (ascii.endsWithIgnoreCase(file_path, ".tar")) return .tar;
759760
if (ascii.endsWithIgnoreCase(file_path, ".tar.gz")) return .@"tar.gz";
760761
if (ascii.endsWithIgnoreCase(file_path, ".tar.xz")) return .@"tar.xz";
762+
if (ascii.endsWithIgnoreCase(file_path, ".tar.zst")) return .@"tar.zst";
761763
return null;
762764
}
763765

@@ -975,6 +977,9 @@ fn unpackResource(
975977
if (ascii.eqlIgnoreCase(content_type, "application/x-xz"))
976978
break :ft .@"tar.xz";
977979

980+
if (ascii.eqlIgnoreCase(content_type, "application/zstd"))
981+
break :ft .@"tar.zst";
982+
978983
if (!ascii.eqlIgnoreCase(content_type, "application/octet-stream")) {
979984
return f.fail(f.location_tok, try eb.printString(
980985
"unrecognized 'Content-Type' header: '{s}'",
@@ -1015,6 +1020,7 @@ fn unpackResource(
10151020
.tar => try unpackTarball(f, tmp_directory.handle, resource.reader()),
10161021
.@"tar.gz" => try unpackTarballCompressed(f, tmp_directory.handle, resource, std.compress.gzip),
10171022
.@"tar.xz" => try unpackTarballCompressed(f, tmp_directory.handle, resource, std.compress.xz),
1023+
.@"tar.zst" => try unpackTarballCompressed(f, tmp_directory.handle, resource, ZstdWrapper),
10181024
.git_pack => unpackGitPack(f, tmp_directory.handle, resource) catch |err| switch (err) {
10191025
error.FetchFailed => return error.FetchFailed,
10201026
error.OutOfMemory => return error.OutOfMemory,
@@ -1026,6 +1032,18 @@ fn unpackResource(
10261032
}
10271033
}
10281034

1035+
// due to slight differences in the API of std.compress.(gzip|xz) and std.compress.zstd, zstd is
1036+
// wrapped for generic use in unpackTarballCompressed: see github.com/ziglang/zig/issues/14739
1037+
const ZstdWrapper = struct {
1038+
fn DecompressType(comptime T: type) type {
1039+
return error{}!std.compress.zstd.DecompressStream(T, .{});
1040+
}
1041+
1042+
fn decompress(allocator: Allocator, reader: anytype) DecompressType(@TypeOf(reader)) {
1043+
return std.compress.zstd.decompressStream(allocator, reader);
1044+
}
1045+
};
1046+
10291047
fn unpackTarballCompressed(
10301048
f: *Fetch,
10311049
out_dir: fs.Dir,

0 commit comments

Comments
 (0)