11#include <botan/lzma.h>
13#include <botan/exceptn.h>
14#include <botan/internal/compress_utils.h>
21class LZMA_Stream :
public Zlib_Style_Stream<lzma_stream, uint8_t> {
24 m_allocator.opaque = alloc();
27 streamp()->allocator = &m_allocator;
30 ~LZMA_Stream()
override { ::lzma_end(streamp()); }
32 LZMA_Stream(
const LZMA_Stream& other) =
delete;
33 LZMA_Stream(LZMA_Stream&& other) =
delete;
34 LZMA_Stream& operator=(
const LZMA_Stream& other) =
delete;
35 LZMA_Stream& operator=(LZMA_Stream&& other) =
delete;
37 bool run(uint32_t flags)
override {
38 lzma_ret rc = ::lzma_code(streamp(),
static_cast<lzma_action
>(flags));
40 if(rc != LZMA_OK && rc != LZMA_STREAM_END) {
44 return (rc == LZMA_STREAM_END);
47 uint32_t run_flag()
const override {
return LZMA_RUN; }
49 uint32_t flush_flag()
const override {
return LZMA_FULL_FLUSH; }
51 uint32_t finish_flag()
const override {
return LZMA_FINISH; }
54 ::lzma_allocator m_allocator;
57class LZMA_Compression_Stream
final :
public LZMA_Stream {
59 explicit LZMA_Compression_Stream(
size_t level) {
62 }
else if(level > 9) {
66 lzma_ret rc = ::lzma_easy_encoder(streamp(),
static_cast<uint32_t
>(level), LZMA_CHECK_CRC64);
74class LZMA_Decompression_Stream
final :
public LZMA_Stream {
76 LZMA_Decompression_Stream() {
77 lzma_ret rc = ::lzma_stream_decoder(streamp(), UINT64_MAX, LZMA_TELL_UNSUPPORTED_CHECK);
87std::unique_ptr<Compression_Stream> LZMA_Compression::make_stream(
size_t level)
const {
88 return std::make_unique<LZMA_Compression_Stream>(level);
91std::unique_ptr<Compression_Stream> LZMA_Decompression::make_stream()
const {
92 return std::make_unique<LZMA_Decompression_Stream>();
static void free(void *self, void *ptr)
static void * malloc(void *self, T n, T size)
int(* final)(unsigned char *, CTX *)