diff options
| author | dweiller <4678790+dweiller@users.noreply.github.com> | 2023-10-16 20:51:30 +1100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-10-17 19:02:00 -0400 |
| commit | f58811a58a592a4e5844e66919b18211dc5f6e59 (patch) | |
| tree | 56966691bf2bacc4ab756c4bb4e654f5d1adf598 /src | |
| parent | 25400fadf868376635ac6f8d0c40ff8f289f5f19 (diff) | |
| download | zig-f58811a58a592a4e5844e66919b18211dc5f6e59.tar.gz zig-f58811a58a592a4e5844e66919b18211dc5f6e59.zip | |
package fetching: support .tar.zst archives
Diffstat (limited to 'src')
| -rw-r--r-- | src/Package/Fetch.zig | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Package/Fetch.zig b/src/Package/Fetch.zig index 7256c5e15c..50468f4c2c 100644 --- a/src/Package/Fetch.zig +++ b/src/Package/Fetch.zig @@ -756,12 +756,14 @@ const FileType = enum { tar, @"tar.gz", @"tar.xz", + @"tar.zst", git_pack, fn fromPath(file_path: []const u8) ?FileType { if (ascii.endsWithIgnoreCase(file_path, ".tar")) return .tar; if (ascii.endsWithIgnoreCase(file_path, ".tar.gz")) return .@"tar.gz"; if (ascii.endsWithIgnoreCase(file_path, ".tar.xz")) return .@"tar.xz"; + if (ascii.endsWithIgnoreCase(file_path, ".tar.zst")) return .@"tar.zst"; return null; } @@ -979,6 +981,9 @@ fn unpackResource( if (ascii.eqlIgnoreCase(content_type, "application/x-xz")) break :ft .@"tar.xz"; + if (ascii.eqlIgnoreCase(content_type, "application/zstd")) + break :ft .@"tar.zst"; + if (!ascii.eqlIgnoreCase(content_type, "application/octet-stream")) { return f.fail(f.location_tok, try eb.printString( "unrecognized 'Content-Type' header: '{s}'", @@ -1019,6 +1024,7 @@ fn unpackResource( .tar => try unpackTarball(f, tmp_directory.handle, resource.reader()), .@"tar.gz" => try unpackTarballCompressed(f, tmp_directory.handle, resource, std.compress.gzip), .@"tar.xz" => try unpackTarballCompressed(f, tmp_directory.handle, resource, std.compress.xz), + .@"tar.zst" => try unpackTarballCompressed(f, tmp_directory.handle, resource, ZstdWrapper), .git_pack => unpackGitPack(f, tmp_directory.handle, resource) catch |err| switch (err) { error.FetchFailed => return error.FetchFailed, error.OutOfMemory => return error.OutOfMemory, @@ -1030,6 +1036,18 @@ fn unpackResource( } } +// due to slight differences in the API of std.compress.(gzip|xz) and std.compress.zstd, zstd is +// wrapped for generic use in unpackTarballCompressed: see github.com/ziglang/zig/issues/14739 +const ZstdWrapper = struct { + fn DecompressType(comptime T: type) type { + return error{}!std.compress.zstd.DecompressStream(T, .{}); + } + + fn decompress(allocator: Allocator, reader: anytype) DecompressType(@TypeOf(reader)) { + return std.compress.zstd.decompressStream(allocator, reader); + } +}; + fn unpackTarballCompressed( f: *Fetch, out_dir: fs.Dir, |
