diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-01-24 15:09:02 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-01-24 15:24:19 -0700 |
| commit | d94613c1d06fbeaf0cee88a04842cda64a10c8f9 (patch) | |
| tree | 9a6350759af9a054a0282b344b36b29ff436a01f /src/Package.zig | |
| parent | ea9ded87582a8b9d0ed3afd3360a1d75f0359a5c (diff) | |
| download | zig-d94613c1d06fbeaf0cee88a04842cda64a10c8f9.tar.gz zig-d94613c1d06fbeaf0cee88a04842cda64a10c8f9.zip | |
support xz compressed tarballs in the package manager
This includes a breaking change:
std.compress.gzip.GzipStream renamed to
std.compress.gzip.Decompress
This follows the same naming convention as std.compress.xz so that the
stream type can be passed as a comptime parameter.
Diffstat (limited to 'src/Package.zig')
| -rw-r--r-- | src/Package.zig | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/Package.zig b/src/Package.zig index f8823cc74e..ebe84b8444 100644 --- a/src/Package.zig +++ b/src/Package.zig @@ -370,14 +370,11 @@ fn fetchAndUnpack( if (mem.endsWith(u8, uri.path, ".tar.gz")) { // I observed the gzip stream to read 1 byte at a time, so I am using a // buffered reader on the front of it. - var br = std.io.bufferedReaderSize(std.crypto.tls.max_ciphertext_record_len, req.reader()); - - var gzip_stream = try std.compress.gzip.gzipStream(gpa, br.reader()); - defer gzip_stream.deinit(); - - try std.tar.pipeToFileSystem(tmp_directory.handle, gzip_stream.reader(), .{ - .strip_components = 1, - }); + try unpackTarball(gpa, &req, tmp_directory.handle, std.compress.gzip); + } else if (mem.endsWith(u8, uri.path, ".tar.xz")) { + // I have not checked what buffer sizes the xz decompression implementation uses + // by default, so the same logic applies for buffering the reader as for gzip. + try unpackTarball(gpa, &req, tmp_directory.handle, std.compress.xz); } else { return reportError( ini, @@ -430,6 +427,22 @@ fn fetchAndUnpack( return createWithDir(gpa, fqn, global_cache_directory, pkg_dir_sub_path, build_zig_basename); } +fn unpackTarball( + gpa: Allocator, + req: *std.http.Client.Request, + out_dir: fs.Dir, + comptime compression: type, +) !void { + var br = std.io.bufferedReaderSize(std.crypto.tls.max_ciphertext_record_len, req.reader()); + + var decompress = try compression.decompress(gpa, br.reader()); + defer decompress.deinit(); + + try std.tar.pipeToFileSystem(out_dir, decompress.reader(), .{ + .strip_components = 1, + }); +} + fn reportError( ini: std.Ini, comp_directory: Compilation.Directory, |
