mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-03 16:16:43 +00:00
LibCompress: Implement a Zlib compressor
This commit is contained in:
parent
42abe1df77
commit
0de0de3536
Notes:
sideshowbarker
2024-07-17 09:49:34 +09:00
Author: https://github.com/krkk
Commit: 0de0de3536
Pull-request: https://github.com/SerenityOS/serenity/pull/14312
Reviewed-by: https://github.com/timschumi
2 changed files with 105 additions and 0 deletions
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue