mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
LibCompress: Add a method that describes a Gzip Header
This can be used to display information about a gzip file that is stored in it's header.
This commit is contained in:
parent
1b6824d296
commit
2119e0fb3f
2 changed files with 15 additions and 0 deletions
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <AK/MemoryStream.h>
|
#include <AK/MemoryStream.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
|
#include <LibCore/DateTime.h>
|
||||||
|
|
||||||
namespace Compress {
|
namespace Compress {
|
||||||
|
|
||||||
|
@ -140,6 +141,19 @@ size_t GzipDecompressor::read(Bytes bytes)
|
||||||
return total_read;
|
return total_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Optional<String> GzipDecompressor::describe_header(ReadonlyBytes bytes)
|
||||||
|
{
|
||||||
|
if (bytes.size() < sizeof(BlockHeader))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
auto& header = *(reinterpret_cast<const BlockHeader*>(bytes.data()));
|
||||||
|
if (!header.valid_magic_number() || !header.supported_by_implementation())
|
||||||
|
return {};
|
||||||
|
|
||||||
|
LittleEndian<u32> original_size = *reinterpret_cast<const u32*>(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)
|
bool GzipDecompressor::read_or_error(Bytes bytes)
|
||||||
{
|
{
|
||||||
if (read(bytes) < bytes.size()) {
|
if (read(bytes) < bytes.size()) {
|
||||||
|
|
|
@ -50,6 +50,7 @@ public:
|
||||||
bool handle_any_error() override;
|
bool handle_any_error() override;
|
||||||
|
|
||||||
static Optional<ByteBuffer> decompress_all(ReadonlyBytes);
|
static Optional<ByteBuffer> decompress_all(ReadonlyBytes);
|
||||||
|
static Optional<String> describe_header(ReadonlyBytes);
|
||||||
static bool is_likely_compressed(ReadonlyBytes bytes);
|
static bool is_likely_compressed(ReadonlyBytes bytes);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue