diff options
author | Martin Ashby <martin@ashbysoft.com> | 2023-09-15 21:45:07 +0100 |
---|---|---|
committer | Martin Ashby <martin@ashbysoft.com> | 2023-09-15 21:45:07 +0100 |
commit | e3f21b6c3253da86dec6cb231581cbbbd4b4a2d7 (patch) | |
tree | 1531e106e91bb1f2827cf2b5dc8b130a5e8e957c /src/main.zig | |
parent | 0c52085be7738b80a28fbced6f4801c171c533d7 (diff) | |
download | zip-zig-e3f21b6c3253da86dec6cb231581cbbbd4b4a2d7.tar.gz zip-zig-e3f21b6c3253da86dec6cb231581cbbbd4b4a2d7.tar.bz2 zip-zig-e3f21b6c3253da86dec6cb231581cbbbd4b4a2d7.tar.xz zip-zig-e3f21b6c3253da86dec6cb231581cbbbd4b4a2d7.zip |
Add more documented (unsupported) compression methods
Diffstat (limited to 'src/main.zig')
-rw-r--r-- | src/main.zig | 35 |
1 files changed, 32 insertions, 3 deletions
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; |