1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#ifndef _ZSTD_WRITER_H
6#define _ZSTD_WRITER_H
7
8#include <cstdint>
9#include <memory>
10#include <vector>
11#include <zstd.h>
12
13class ZstdWriter {
14public:
15 ZstdWriter(void);
16 ~ZstdWriter(void);
17 int open(const char* filename, int compress_level);
18 int write(const void* buf, size_t size);
19 int close(void);
20 bool valid(void) { return (fout != NULL);}
21
22private:
23 int flush(const void* buf, size_t size);
24
25 FILE* fout;
26 ZSTD_CStream* cstream;
27 size_t pos;
28 size_t total;
29 size_t buffInSize;
30 std::unique_ptr<char[]> buffIn;
31 size_t buffOutSize;
32 std::unique_ptr<char[]> buffOut;
33};
34
35#endif /*end #ifndef _ZSTD_WRITER_H*/
36