authorgravatar for h_n91@hotmail.comDraagrenKirneh <h_n91@hotmail.com> 2023-04-23 22:29:23+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-05-03 08:23:50+03:00
logb643c5dc917e0f1c52e893bc0046aaddb7ca6fee
tree16b78838dab3c921cc3a1d77040ec0582d49c428
parentb9841750f91604020268549fc5e2c6b10c1f8477

Change compression detection to use content-type instead of the url ending


1 files changed, 8 insertions(+), 2 deletions(-)

src/Package.zig+8-2
......@@ -5,6 +5,7 @@ const std = @import("std");
55const fs = std.fs;
66const mem = std.mem;
77const Allocator = mem.Allocator;
8const ascii = std.ascii;
89const assert = std.debug.assert;
910const log = std.log.scoped(.package);
1011const main = @import("main.zig");
......@@ -488,11 +489,16 @@ fn fetchAndUnpack(
488489 try req.start();
489490 try req.wait();
490491
491 if (mem.endsWith(u8, uri.path, ".tar.gz")) {
492 const content_type = req.response.headers.getFirstValue("Content-Type") orelse
493 return report.fail(dep.url_tok, "missing Content-Type for '{s}'", .{uri.path});
494
495 if (ascii.eqlIgnoreCase(content_type, "application/gzip") or
496 ascii.eqlIgnoreCase(content_type, "application/x-gzip"))
497 {
492498 // I observed the gzip stream to read 1 byte at a time, so I am using a
493499 // buffered reader on the front of it.
494500 try unpackTarball(gpa, &req, tmp_directory.handle, std.compress.gzip);
495 } else if (mem.endsWith(u8, uri.path, ".tar.xz")) {
501 } else if (ascii.eqlIgnoreCase(content_type, "application/x-xz")) {
496502 // I have not checked what buffer sizes the xz decompression implementation uses
497503 // by default, so the same logic applies for buffering the reader as for gzip.
498504 try unpackTarball(gpa, &req, tmp_directory.handle, std.compress.xz);