#ifndef TILE_BASE_COMPRESSION_GZIP_H
#define TILE_BASE_COMPRESSION_GZIP_H

#pragma once

#include <memory>

#include "tile/base/compression/compression.h"

namespace tile {
namespace compression {
namespace detail {
struct ZStream;
}// namespace detail

class GzipCompressor : public Compressor {
public:
    bool Compress(const void *src, std::size_t size, CompressionOutputStream *out) override;
    bool Compress(const NoncontiguousBuffer &bytes, CompressionOutputStream *out) override;

private:
    bool Append(const void *buffer, std::size_t size);
    bool Flush();
    bool Init(CompressionOutputStream *out);
    bool Release();
    std::unique_ptr<detail::ZStream> stream_;
    CompressionOutputStream *out_ = nullptr;
};

class GzipDecompressor : public Decompressor {
public:
    bool Decompress(const void *src, std::size_t size, CompressionOutputStream *out) override;
    bool Decompress(const NoncontiguousBuffer &compressed, CompressionOutputStream *out) override;

private:
    bool Append(const void *buffer, std::size_t size);
    bool Flush();
    bool Init(CompressionOutputStream *out);
    bool Release();
    std::unique_ptr<detail::ZStream> stream_;
    CompressionOutputStream *out_ = nullptr;
};

}// namespace compression
}// namespace tile

#endif// TILE_BASE_COMPRESSION_GZIP_H
