#Unable to unzip

1 messages · Page 1 of 1 (latest)

young violet
#

I am trying to unzip the Unicode database file in XML format.

I managed to download the file and unzip it using the following command gzip --decompress --stdout zig-cache/unicode/ucd.all.grouped.xml | cat

When I tried to use the std.compress.gzip library it did not work telling me error.BadHeader. Here is the code I am using:

const dir = "zig-cache/unicode/";
const name = "ucd.all.grouped.xml";

const cwd = std.fs.cwd();
try cwd.makePath(dir);

var file = try cwd.createFile(dir ++ name, .{});
defer file.close();

var buffered = std.io.bufferedWriter(file.writer());
var writer = buffered.writer();

var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer std.debug.assert(gpa.deinit() == .ok);
const allocator = gpa.allocator();

var client = http.Client{ .allocator = allocator };
defer client.deinit();

const url = "https://www.unicode.org/Public/15.1.0/ucdxml/ucd.all.grouped.zip";
const uri = std.Uri.parse(url) catch unreachable;

var headers = http.Headers{ .allocator = allocator };
defer headers.deinit();

try headers.append("accept", "application/zip");
try headers.append("accept-encoding", "identity");

var req = try client.request(.GET, uri, headers, .{});
defer req.deinit();

try req.start();
try req.wait();

std.debug.print("{}\r\n", .{req.headers});
std.debug.print("{}\r\n", .{req.response.headers});

var decompressor = try std.compress.gzip.decompress(allocator, req.reader()); // BadHeader
var reader = decompressor.reader();

while (reader.readByte()) |byte| {
    try writer.writeByte(byte);
} else |err| {
    switch (err) {
        error.EndOfStream => {},
        else => return err,
    }
}

try buffered.flush();
#

P.S. I altro tried using zlib and deflate but none of the worked

runic terrace
#

the .zip file extension would tend to imply it’s a zip file, not a gzip file (which tends to be .gz)

runic terrace
#

a quick check verifies this assumption, ucd.all.grouped.zip is in fact a zip file, not gzip, zlib or raw deflate