diff --git a/Userland/Libraries/LibArchive/Zip.cpp b/Userland/Libraries/LibArchive/Zip.cpp index 01097365cf..d5aa5d112f 100644 --- a/Userland/Libraries/LibArchive/Zip.cpp +++ b/Userland/Libraries/LibArchive/Zip.cpp @@ -9,6 +9,11 @@ namespace Archive { +OutputStream& operator<<(OutputStream& stream, ZipCompressionMethod method) +{ + return stream << to_underlying(method); +} + bool Zip::find_end_of_central_directory_offset(ReadonlyBytes buffer, size_t& offset) { for (size_t backwards_offset = 0; backwards_offset <= UINT16_MAX; backwards_offset++) // the file may have a trailing comment of an arbitrary 16 bit length @@ -90,7 +95,7 @@ bool Zip::for_each_member(Function callback null_terminated_name[central_directory_record.name_length] = 0; member.name = String { null_terminated_name }; member.compressed_data = { local_file_header.compressed_data, central_directory_record.compressed_size }; - member.compression_method = static_cast(central_directory_record.compression_method); + member.compression_method = central_directory_record.compression_method; member.uncompressed_size = central_directory_record.uncompressed_size; member.crc32 = central_directory_record.crc32; member.is_directory = central_directory_record.external_attributes & zip_directory_external_attribute || member.name.ends_with('/'); // FIXME: better directory detection diff --git a/Userland/Libraries/LibArchive/Zip.h b/Userland/Libraries/LibArchive/Zip.h index d7a62296ea..1575743154 100644 --- a/Userland/Libraries/LibArchive/Zip.h +++ b/Userland/Libraries/LibArchive/Zip.h @@ -70,13 +70,27 @@ struct [[gnu::packed]] EndOfCentralDirectory { } }; +enum class ZipCompressionMethod : u16 { + Store = 0, + Shrink = 1, + Reduce1 = 2, + Reduce2 = 3, + Reduce3 = 4, + Reduce4 = 5, + Implode = 6, + Reserved = 7, + Deflate = 8 +}; + +OutputStream& operator<<(OutputStream& stream, ZipCompressionMethod method); + struct [[gnu::packed]] CentralDirectoryRecord { static constexpr Array signature = { 0x50, 0x4b, 0x01, 0x02 }; // 'PK\x01\x02' u16 made_by_version; u16 minimum_version; u16 general_purpose_flags; - u16 compression_method; + ZipCompressionMethod compression_method; u16 modification_time; u16 modification_date; u32 crc32; @@ -192,18 +206,6 @@ struct [[gnu::packed]] LocalFileHeader { } }; -enum ZipCompressionMethod : u16 { - Store = 0, - Shrink = 1, - Reduce1 = 2, - Reduce2 = 3, - Reduce3 = 4, - Reduce4 = 5, - Implode = 6, - Reserved = 7, - Deflate = 8 -}; - struct ZipMember { String name; ReadonlyBytes compressed_data; // TODO: maybe the decompression/compression should be handled by LibArchive instead of the user?