10#include "ll/api/Expected.h"
11#include "ll/api/base/Macro.h"
13namespace ll::inline utils::compress_utils {
16enum class CompressFormat :
int {
28enum class CompressLevel :
int {
36LLNDAPI std::string_view extensionOf(CompressFormat format);
40using SinkFn = std::function<Expected<>(std::string_view)>;
49 std::unique_ptr<Impl> impl;
53 Compressor(SinkFn sink, CompressFormat format = CompressFormat::Gzip, CompressLevel level = CompressLevel::Default);
57 LLAPI Compressor(Compressor&&)
noexcept;
58 LLAPI Compressor& operator=(Compressor&&)
noexcept;
63 LLAPI Expected<> write(std::string_view data);
73 std::unique_ptr<Impl> impl;
76 LLAPI Decompressor(SinkFn sink, CompressFormat format = CompressFormat::Gzip);
78 LLAPI ~Decompressor();
80 LLAPI Decompressor(Decompressor&&)
noexcept;
81 LLAPI Decompressor& operator=(Decompressor&&)
noexcept;
83 LLNDAPI Expected<> status()
const;
85 LLAPI Expected<> write(std::string_view data);
93LLNDAPI Expected<std::string> compress(
94 std::string_view data,
95 CompressFormat format = CompressFormat::Gzip,
96 CompressLevel level = CompressLevel::Default
103LLNDAPI Expected<std::string>
104 decompress(std::string_view data, CompressFormat format = CompressFormat::Gzip,
size_t maxSize = 0);
109LLNDAPI Expected<> compressFile(
110 std::filesystem::path
const& src,
111 std::filesystem::path
const& dst,
112 CompressFormat format = CompressFormat::Gzip,
113 CompressLevel level = CompressLevel::Default
117LLNDAPI Expected<> decompressFile(
118 std::filesystem::path
const& src,
119 std::filesystem::path
const& dst,
120 CompressFormat format = CompressFormat::Gzip
LLAPI Expected finish()
Ends the stream. Writing afterwards is an error.
LLNDAPI Expected status() const
Fails if the codec for the requested format is unavailable, so check this before writing.
LLAPI Expected finish()
Confirms the stream ended cleanly. Fails on a truncated or trailing-garbage input.