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");...@@ -5,6 +5,7 @@ const std = @import("std");
5const fs = std.fs;5const fs = std.fs;
6const mem = std.mem;6const mem = std.mem;
7const Allocator = mem.Allocator;7const Allocator = mem.Allocator;
8const ascii = std.ascii;
8const assert = std.debug.assert;9const assert = std.debug.assert;
9const log = std.log.scoped(.package);10const log = std.log.scoped(.package);
10const main = @import("main.zig");11const main = @import("main.zig");
...@@ -488,11 +489,16 @@ fn fetchAndUnpack(...@@ -488,11 +489,16 @@ fn fetchAndUnpack(
488 try req.start();489 try req.start();
489 try req.wait();490 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 {
492 // I observed the gzip stream to read 1 byte at a time, so I am using a498 // I observed the gzip stream to read 1 byte at a time, so I am using a
493 // buffered reader on the front of it.499 // buffered reader on the front of it.
494 try unpackTarball(gpa, &req, tmp_directory.handle, std.compress.gzip);500 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")) {
496 // I have not checked what buffer sizes the xz decompression implementation uses502 // I have not checked what buffer sizes the xz decompression implementation uses
497 // by default, so the same logic applies for buffering the reader as for gzip.503 // by default, so the same logic applies for buffering the reader as for gzip.
498 try unpackTarball(gpa, &req, tmp_directory.handle, std.compress.xz);504 try unpackTarball(gpa, &req, tmp_directory.handle, std.compress.xz);