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
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibCompress/Zlib.h>
|
|
|
|
|
2025-03-01 17:37:59 +01:00
|
|
|
#include <zlib.h>
|
|
|
|
|
2020-08-01 22:01:39 +02:00
|
|
|
namespace Compress {
|
|
|
|
|
2023-06-08 19:35:44 +02:00
|
|
|
ErrorOr<NonnullOwnPtr<ZlibDecompressor>> ZlibDecompressor::create(MaybeOwned<Stream> stream)
|
2020-08-01 22:01:39 +02:00
|
|
|
{
|
2025-03-01 17:37:59 +01:00
|
|
|
auto buffer = TRY(AK::FixedArray<u8>::create(16 * 1024));
|
|
|
|
auto zstream = TRY(GenericZlibDecompressor::new_z_stream(MAX_WBITS));
|
|
|
|
return adopt_nonnull_own_or_enomem(new (nothrow) ZlibDecompressor(move(buffer), move(stream), zstream));
|
2022-06-17 09:26:35 +02:00
|
|
|
}
|
|
|
|
|
2025-03-01 17:37:59 +01:00
|
|
|
ErrorOr<ByteBuffer> ZlibDecompressor::decompress_all(ReadonlyBytes bytes)
|
2022-06-17 09:26:35 +02:00
|
|
|
{
|
2025-03-01 17:37:59 +01:00
|
|
|
return ::Compress::decompress_all<ZlibDecompressor>(bytes);
|
2022-06-17 09:26:35 +02:00
|
|
|
}
|
|
|
|
|
2025-03-01 17:37:59 +01:00
|
|
|
ErrorOr<NonnullOwnPtr<ZlibCompressor>> ZlibCompressor::create(MaybeOwned<Stream> stream, GenericZlibCompressionLevel compression_level)
|
2022-06-17 09:26:35 +02:00
|
|
|
{
|
2025-03-01 17:37:59 +01:00
|
|
|
auto buffer = TRY(AK::FixedArray<u8>::create(16 * 1024));
|
|
|
|
auto zstream = TRY(GenericZlibCompressor::new_z_stream(MAX_WBITS, compression_level));
|
|
|
|
return adopt_nonnull_own_or_enomem(new (nothrow) ZlibCompressor(move(buffer), move(stream), zstream));
|
2022-12-26 18:42:39 +01:00
|
|
|
}
|
2022-06-17 09:26:35 +02:00
|
|
|
|
2025-03-01 17:37:59 +01:00
|
|
|
ErrorOr<ByteBuffer> ZlibCompressor::compress_all(ReadonlyBytes bytes, GenericZlibCompressionLevel compression_level)
|
2022-12-26 18:42:39 +01:00
|
|
|
{
|
2025-03-01 17:37:59 +01:00
|
|
|
return ::Compress::compress_all<ZlibCompressor>(bytes, compression_level);
|
2022-06-17 09:26:35 +02:00
|
|
|
}
|
|
|
|
|
2020-08-01 22:01:39 +02:00
|
|
|
}
|