mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-23 13:05:12 +00:00
Utilities: Use GzipDecompressor::describe_header for gzip descriptions
This commit is contained in:
parent
2119e0fb3f
commit
284730c002
Notes:
sideshowbarker
2024-07-18 18:34:19 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/284730c0027 Pull-request: https://github.com/SerenityOS/serenity/pull/6929
2 changed files with 20 additions and 1 deletions
|
@ -56,4 +56,4 @@ target_link_libraries(gzip LibCompress)
|
|||
target_link_libraries(gunzip LibCompress)
|
||||
target_link_libraries(CppParserTest LibCpp LibGUI)
|
||||
target_link_libraries(PreprocessorTest LibCpp LibGUI)
|
||||
target_link_libraries(file LibGfx LibIPC)
|
||||
target_link_libraries(file LibGfx LibIPC LibCompress)
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <AK/MappedFile.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibCompress/Gzip.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/FileStream.h>
|
||||
#include <LibCore/MimeData.h>
|
||||
|
@ -34,9 +35,27 @@ static Optional<String> image_details(const String& description, const String& p
|
|||
return String::formatted("{}, {} x {}", description, image_decoder->width(), image_decoder->height());
|
||||
}
|
||||
|
||||
static Optional<String> gzip_details(String description, const String& path)
|
||||
{
|
||||
auto file_or_error = MappedFile::map(path);
|
||||
if (file_or_error.is_error())
|
||||
return {};
|
||||
|
||||
auto& mapped_file = *file_or_error.value();
|
||||
if (!Compress::GzipDecompressor::is_likely_compressed(mapped_file.bytes()))
|
||||
return {};
|
||||
|
||||
auto gzip_details = Compress::GzipDecompressor::describe_header(mapped_file.bytes());
|
||||
if (!gzip_details.has_value())
|
||||
return {};
|
||||
|
||||
return String::formatted("{}, {}", description, gzip_details.value());
|
||||
}
|
||||
|
||||
#define ENUMERATE_MIME_TYPE_DESCRIPTIONS \
|
||||
__ENUMERATE_MIME_TYPE_DESCRIPTION("application/javascript", "JavaScript source", description_only) \
|
||||
__ENUMERATE_MIME_TYPE_DESCRIPTION("application/json", "JSON data", description_only) \
|
||||
__ENUMERATE_MIME_TYPE_DESCRIPTION("extra/gzip", "gzip compressed data", gzip_details) \
|
||||
__ENUMERATE_MIME_TYPE_DESCRIPTION("image/bmp", "BMP image data", image_details) \
|
||||
__ENUMERATE_MIME_TYPE_DESCRIPTION("image/gif", "GIF image data", image_details) \
|
||||
__ENUMERATE_MIME_TYPE_DESCRIPTION("image/jpeg", "JPEG image data", image_details) \
|
||||
|
|
Loading…
Add table
Reference in a new issue