From e3f21b6c3253da86dec6cb231581cbbbd4b4a2d7 Mon Sep 17 00:00:00 2001 From: Martin Ashby Date: Fri, 15 Sep 2023 21:45:07 +0100 Subject: Add more documented (unsupported) compression methods --- src/main.zig | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'src/main.zig') diff --git a/src/main.zig b/src/main.zig index 34cb59c..20c939a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -6,10 +6,33 @@ const std = @import("std"); const ZipFile = struct { const CompressionMethod = enum(u16) { store = 0, + shrink = 1, + reduce_1 = 2, + reduce_2 = 3, + reduce_3 = 4, + reduce_4 = 5, + implode = 6, + reserved_1 = 7, deflate = 8, + deflate64 = 9, + pkware_implode = 10, + reserved_2 = 11, + bzip2 = 12, + reserved_3 = 13, lzma = 14, + reserved_4 = 15, + ibm_zos_zmpsc = 16, + reserved_5 = 17, + ibm_terse = 18, + ibm_lz77_z = 19, + zstd_deprecated = 20, zstd = 93, + mp3 = 94, xz = 95, + jpeg = 96, + wavpack = 97, + ppmd_version_i_rev1 = 98, + aex_encryption_marker = 99, }; // [local file header 1] // [encryption header 1] @@ -33,7 +56,6 @@ const ZipFile = struct { // [zip64 end of central directory locator] // [end of central directory record] allocator: std.mem.Allocator, - is_zip_64: bool = false, end_of_central_directory_record: EndOfCentralDirectoryRecord, central_directory_headers: []CentralDirectoryHeader, fn from(allocator: std.mem.Allocator, file_or_stream: anytype) !ZipFile { @@ -101,17 +123,24 @@ const ZipFile = struct { var lr = std.io.limitedReader(reader, lfh.compressed_size); var limited_reader = lr.reader(); switch (lfh.compression_method) { - .store => { // no compression (store) + .store => { var writer = stream_or_file_out.writer(); try pump(limited_reader, writer, lfh.uncompressed_size, lfh.crc32); }, - .deflate => { // deflate + .deflate => { var decomp = try std.compress.deflate.decompressor(self.allocator, limited_reader, null); defer decomp.deinit(); var decomp_reader = decomp.reader(); var writer = stream_or_file_out.writer(); try pump(decomp_reader, writer, lfh.uncompressed_size, lfh.crc32); }, + .lzma => { + var decomp = try std.compress.lzma.decompress(self.allocator, limited_reader); + defer decomp.deinit(); + var decomp_reader = decomp.reader(); + var writer = stream_or_file_out.writer(); + try pump(decomp_reader, writer, lfh.uncompressed_size, lfh.crc32); + }, else => { std.log.err("compression method {} not supported", .{lfh.compression_method}); return error.CompressionMethodNotSupported; -- cgit v1.2.3-ZIG