diff --git a/Userland/Libraries/LibCompress/Gzip.cpp b/Userland/Libraries/LibCompress/Gzip.cpp index 70ad0bcff3..9d62505c2a 100644 --- a/Userland/Libraries/LibCompress/Gzip.cpp +++ b/Userland/Libraries/LibCompress/Gzip.cpp @@ -9,6 +9,7 @@ #include #include +#include namespace Compress { @@ -140,6 +141,19 @@ size_t GzipDecompressor::read(Bytes bytes) return total_read; } +Optional GzipDecompressor::describe_header(ReadonlyBytes bytes) +{ + if (bytes.size() < sizeof(BlockHeader)) + return {}; + + auto& header = *(reinterpret_cast(bytes.data())); + if (!header.valid_magic_number() || !header.supported_by_implementation()) + return {}; + + LittleEndian original_size = *reinterpret_cast(bytes.offset(bytes.size() - sizeof(u32))); + return String::formatted("last modified: {}, original size {}", Core::DateTime::from_timestamp(header.modification_time).to_string(), (u32)original_size); +} + bool GzipDecompressor::read_or_error(Bytes bytes) { if (read(bytes) < bytes.size()) { diff --git a/Userland/Libraries/LibCompress/Gzip.h b/Userland/Libraries/LibCompress/Gzip.h index 8d0f9973ae..635ba99f9e 100644 --- a/Userland/Libraries/LibCompress/Gzip.h +++ b/Userland/Libraries/LibCompress/Gzip.h @@ -50,6 +50,7 @@ public: bool handle_any_error() override; static Optional decompress_all(ReadonlyBytes); + static Optional describe_header(ReadonlyBytes); static bool is_likely_compressed(ReadonlyBytes bytes); private: