mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:17:44 +00:00
Utilities: Use GzipDecompressor::describe_header for gzip descriptions
This commit is contained in:
parent
2119e0fb3f
commit
284730c002
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(gunzip LibCompress)
|
||||||
target_link_libraries(CppParserTest LibCpp LibGUI)
|
target_link_libraries(CppParserTest LibCpp LibGUI)
|
||||||
target_link_libraries(PreprocessorTest 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/MappedFile.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
#include <LibCompress/Gzip.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/FileStream.h>
|
#include <LibCore/FileStream.h>
|
||||||
#include <LibCore/MimeData.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());
|
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 \
|
#define ENUMERATE_MIME_TYPE_DESCRIPTIONS \
|
||||||
__ENUMERATE_MIME_TYPE_DESCRIPTION("application/javascript", "JavaScript source", description_only) \
|
__ENUMERATE_MIME_TYPE_DESCRIPTION("application/javascript", "JavaScript source", description_only) \
|
||||||
__ENUMERATE_MIME_TYPE_DESCRIPTION("application/json", "JSON data", 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/bmp", "BMP image data", image_details) \
|
||||||
__ENUMERATE_MIME_TYPE_DESCRIPTION("image/gif", "GIF 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) \
|
__ENUMERATE_MIME_TYPE_DESCRIPTION("image/jpeg", "JPEG image data", image_details) \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue