Skip to content

Commit f58811a

Browse files
dweillerandrewrk
authored andcommitted
package fetching: support .tar.zst archives
1 parent 25400fa commit f58811a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Package/Fetch.zig

+18
Original file line numberDiff line numberDiff line change
@@ -756,12 +756,14 @@ const FileType = enum {
756756
tar,
757757
@"tar.gz",
758758
@"tar.xz",
759+
@"tar.zst",
759760
git_pack,
760761

761762
fn fromPath(file_path: []const u8) ?FileType {
762763
if (ascii.endsWithIgnoreCase(file_path, ".tar")) return .tar;
763764
if (ascii.endsWithIgnoreCase(file_path, ".tar.gz")) return .@"tar.gz";
764765
if (ascii.endsWithIgnoreCase(file_path, ".tar.xz")) return .@"tar.xz";
766+
if (ascii.endsWithIgnoreCase(file_path, ".tar.zst")) return .@"tar.zst";
765767
return null;
766768
}
767769

@@ -979,6 +981,9 @@ fn unpackResource(
979981
if (ascii.eqlIgnoreCase(content_type, "application/x-xz"))
980982
break :ft .@"tar.xz";
981983

984+
if (ascii.eqlIgnoreCase(content_type, "application/zstd"))
985+
break :ft .@"tar.zst";
986+
982987
if (!ascii.eqlIgnoreCase(content_type, "application/octet-stream")) {
983988
return f.fail(f.location_tok, try eb.printString(
984989
"unrecognized 'Content-Type' header: '{s}'",
@@ -1019,6 +1024,7 @@ fn unpackResource(
10191024
.tar => try unpackTarball(f, tmp_directory.handle, resource.reader()),
10201025
.@"tar.gz" => try unpackTarballCompressed(f, tmp_directory.handle, resource, std.compress.gzip),
10211026
.@"tar.xz" => try unpackTarballCompressed(f, tmp_directory.handle, resource, std.compress.xz),
1027+
.@"tar.zst" => try unpackTarballCompressed(f, tmp_directory.handle, resource, ZstdWrapper),
10221028
.git_pack => unpackGitPack(f, tmp_directory.handle, resource) catch |err| switch (err) {
10231029
error.FetchFailed => return error.FetchFailed,
10241030
error.OutOfMemory => return error.OutOfMemory,
@@ -1030,6 +1036,18 @@ fn unpackResource(
10301036
}
10311037
}
10321038

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

0 commit comments

Comments
 (0)