Skip to content

Commit

Permalink
Libraries: Change enums to enum classes in LibArchive
Browse files Browse the repository at this point in the history
  • Loading branch information
ldm5180 authored and awesomekling committed Mar 18, 2022
1 parent 3eb6016 commit be360db
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
7 changes: 6 additions & 1 deletion Userland/Libraries/LibArchive/Zip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -90,7 +95,7 @@ bool Zip::for_each_member(Function<IterationDecision(const ZipMember&)> 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<ZipCompressionMethod>(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
Expand Down
28 changes: 15 additions & 13 deletions Userland/Libraries/LibArchive/Zip.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8, signature_length> 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;
Expand Down Expand Up @@ -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?
Expand Down

0 comments on commit be360db

Please sign in to comment.