diff options
author | Karol Kosek <krkk@serenityos.org> | 2022-06-17 09:26:35 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-06-30 12:26:49 +0100 |
commit | 0de0de35367d130dd72fe11b489cf50d22b68933 (patch) | |
tree | b9d9c160a884500ca9ac7891a5fc58b39399d7bb /Userland/Libraries/LibCompress/Zlib.h | |
parent | 42abe1df777ac3b940c332087c3da5e435cc8936 (diff) | |
download | serenity-0de0de35367d130dd72fe11b489cf50d22b68933.zip |
LibCompress: Implement a Zlib compressor
Diffstat (limited to 'Userland/Libraries/LibCompress/Zlib.h')
-rw-r--r-- | Userland/Libraries/LibCompress/Zlib.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCompress/Zlib.h b/Userland/Libraries/LibCompress/Zlib.h index e9d1dd5631..c526d5c123 100644 --- a/Userland/Libraries/LibCompress/Zlib.h +++ b/Userland/Libraries/LibCompress/Zlib.h @@ -6,10 +6,13 @@ #pragma once +#include <AK/BitStream.h> #include <AK/ByteBuffer.h> #include <AK/Optional.h> +#include <AK/OwnPtr.h> #include <AK/Span.h> #include <AK/Types.h> +#include <LibCrypto/Checksum/Adler32.h> namespace Compress { @@ -57,4 +60,24 @@ private: ReadonlyBytes m_data_bytes; }; +class ZlibCompressor : public OutputStream { +public: + ZlibCompressor(OutputStream&, ZlibCompressionLevel = ZlibCompressionLevel::Default); + ~ZlibCompressor(); + + size_t write(ReadonlyBytes) override; + bool write_or_error(ReadonlyBytes) override; + void finish(); + + static Optional<ByteBuffer> compress_all(ReadonlyBytes bytes, ZlibCompressionLevel = ZlibCompressionLevel::Default); + +private: + void write_header(ZlibCompressionMethod, ZlibCompressionLevel); + + bool m_finished { false }; + OutputBitStream m_output_stream; + OwnPtr<OutputStream> m_compressor; + Crypto::Checksum::Adler32 m_adler32_checksum; +}; + } |