1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 07:54:58 +00:00

LibArchive: Extract logic for calculating ZIP statistics

This commit is contained in:
Sam Atkins 2023-07-27 14:21:12 +01:00 committed by Sam Atkins
parent 60e35f2a97
commit 8d53442187
5 changed files with 63 additions and 25 deletions

View file

@ -146,22 +146,17 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (list_files) {
outln(" Length Date Time Name");
outln("--------- ---------- -------- ----");
u32 members_count = 0;
u64 total_size = 0;
TRY(zip_file->for_each_member([&](auto zip_member) -> ErrorOr<IterationDecision> {
members_count++;
auto time = time_from_packed_dos(zip_member.modification_date, zip_member.modification_time);
auto time_str = TRY(Core::DateTime::from_timestamp(time.seconds_since_epoch()).to_string());
total_size += zip_member.uncompressed_size;
outln("{:>9} {} {}", zip_member.uncompressed_size, time_str, zip_member.name);
return IterationDecision::Continue;
}));
auto statistics = TRY(zip_file->calculate_statistics());
outln("--------- ----");
outln("{:>9} {} files", total_size, members_count);
outln("{:>9} {} files", statistics.total_uncompressed_bytes(), statistics.member_count());
return 0;
}