2020-08-01 22:01:39 +02:00
|
|
|
/*
|
2021-04-28 22:46:44 +02:00
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2025-03-01 17:37:59 +01:00
|
|
|
* Copyright (c) 2025, Altomani Gianluca <altomanigianluca@gmail.com>
|
2020-08-01 22:01:39 +02:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-01 22:01:39 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-08-26 14:22:25 +02:00
|
|
|
#include <AK/ByteBuffer.h>
|
2023-01-22 04:24:18 +01:00
|
|
|
#include <AK/MaybeOwned.h>
|
2023-02-09 03:11:50 +01:00
|
|
|
#include <AK/Stream.h>
|
2025-03-01 17:37:59 +01:00
|
|
|
#include <LibCompress/GenericZlib.h>
|
2020-08-01 22:01:39 +02:00
|
|
|
|
|
|
|
namespace Compress {
|
2020-08-26 14:22:25 +02:00
|
|
|
|
2025-03-01 17:37:59 +01:00
|
|
|
class ZlibDecompressor final : public GenericZlibDecompressor {
|
2020-08-01 22:01:39 +02:00
|
|
|
public:
|
2023-06-08 19:35:44 +02:00
|
|
|
static ErrorOr<NonnullOwnPtr<ZlibDecompressor>> create(MaybeOwned<Stream>);
|
2025-03-01 17:37:59 +01:00
|
|
|
static ErrorOr<ByteBuffer> decompress_all(ReadonlyBytes);
|
2020-08-26 14:22:25 +02:00
|
|
|
|
2020-08-01 22:01:39 +02:00
|
|
|
private:
|
2025-03-01 17:37:59 +01:00
|
|
|
ZlibDecompressor(AK::FixedArray<u8> buffer, MaybeOwned<Stream> stream, z_stream* zstream)
|
|
|
|
: GenericZlibDecompressor(move(buffer), move(stream), zstream)
|
|
|
|
{
|
|
|
|
}
|
2020-08-01 22:01:39 +02:00
|
|
|
};
|
2020-08-18 20:49:59 +02:00
|
|
|
|
2025-03-01 17:37:59 +01:00
|
|
|
class ZlibCompressor final : public GenericZlibCompressor {
|
2022-06-17 09:26:35 +02:00
|
|
|
public:
|
2025-03-01 17:37:59 +01:00
|
|
|
static ErrorOr<NonnullOwnPtr<ZlibCompressor>> create(MaybeOwned<Stream>, GenericZlibCompressionLevel = GenericZlibCompressionLevel::Default);
|
|
|
|
static ErrorOr<ByteBuffer> compress_all(ReadonlyBytes, GenericZlibCompressionLevel = GenericZlibCompressionLevel::Default);
|
2022-06-17 09:26:35 +02:00
|
|
|
|
|
|
|
private:
|
2025-03-01 17:37:59 +01:00
|
|
|
ZlibCompressor(AK::FixedArray<u8> buffer, MaybeOwned<Stream> stream, z_stream* zstream)
|
|
|
|
: GenericZlibCompressor(move(buffer), move(stream), zstream)
|
|
|
|
{
|
|
|
|
}
|
2022-06-17 09:26:35 +02:00
|
|
|
};
|
|
|
|
|
2020-08-01 22:01:39 +02:00
|
|
|
}
|