@@ -752,12 +752,14 @@ const FileType = enum {
752
752
tar ,
753
753
@"tar.gz" ,
754
754
@"tar.xz" ,
755
+ @"tar.zst" ,
755
756
git_pack ,
756
757
757
758
fn fromPath (file_path : []const u8 ) ? FileType {
758
759
if (ascii .endsWithIgnoreCase (file_path , ".tar" )) return .tar ;
759
760
if (ascii .endsWithIgnoreCase (file_path , ".tar.gz" )) return .@"tar.gz" ;
760
761
if (ascii .endsWithIgnoreCase (file_path , ".tar.xz" )) return .@"tar.xz" ;
762
+ if (ascii .endsWithIgnoreCase (file_path , ".tar.zst" )) return .@"tar.zst" ;
761
763
return null ;
762
764
}
763
765
@@ -975,6 +977,9 @@ fn unpackResource(
975
977
if (ascii .eqlIgnoreCase (content_type , "application/x-xz" ))
976
978
break :ft .@"tar.xz" ;
977
979
980
+ if (ascii .eqlIgnoreCase (content_type , "application/zstd" ))
981
+ break :ft .@"tar.zst" ;
982
+
978
983
if (! ascii .eqlIgnoreCase (content_type , "application/octet-stream" )) {
979
984
return f .fail (f .location_tok , try eb .printString (
980
985
"unrecognized 'Content-Type' header: '{s}'" ,
@@ -1015,6 +1020,7 @@ fn unpackResource(
1015
1020
.tar = > try unpackTarball (f , tmp_directory .handle , resource .reader ()),
1016
1021
.@"tar.gz" = > try unpackTarballCompressed (f , tmp_directory .handle , resource , std .compress .gzip ),
1017
1022
.@"tar.xz" = > try unpackTarballCompressed (f , tmp_directory .handle , resource , std .compress .xz ),
1023
+ .@"tar.zst" = > try unpackTarballCompressed (f , tmp_directory .handle , resource , ZstdWrapper ),
1018
1024
.git_pack = > unpackGitPack (f , tmp_directory .handle , resource ) catch | err | switch (err ) {
1019
1025
error .FetchFailed = > return error .FetchFailed ,
1020
1026
error .OutOfMemory = > return error .OutOfMemory ,
@@ -1026,6 +1032,18 @@ fn unpackResource(
1026
1032
}
1027
1033
}
1028
1034
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
+
1029
1047
fn unpackTarballCompressed (
1030
1048
f : * Fetch ,
1031
1049
out_dir : fs.Dir ,
0 commit comments