scc 2026.07
SystemC components library
zstd_streambuf.h
1/*******************************************************************************
2 * Copyright 2026 MINRES Technologies GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16
17#ifndef _UTIL_ZSTD_STREAMBUF_H_
18#define _UTIL_ZSTD_STREAMBUF_H_
19
20#include <cctype>
21#include <climits>
22#include <iostream>
23#include <string>
24#include <sys/stat.h>
25#include <vector>
26#include <zstd.h>
27
28namespace util {
29// ============================================================
30// ZSTD
31// ============================================================
32
33class zstd_streambuf : public std::streambuf {
34public:
35 explicit zstd_streambuf(const std::string& path);
36
37 ~zstd_streambuf() override;
38
39protected:
40 int_type underflow() override;
41
42private:
43 FILE* file_;
44 ZSTD_DCtx* dctx_;
45 std::vector<char> buffer_;
46 std::vector<char> inbuf_;
47};
48
49class zstd_stream : public std::istream {
50public:
51 zstd_stream() = delete;
52 explicit zstd_stream(const std::string& path)
53 : std::istream(&buf_)
54 , buf_(path) {
55 rdbuf(&buf_);
56 }
57
58private:
59 zstd_streambuf buf_;
60};
61
62} // namespace util
63#endif // _UTIL_ZSTD_STREAMBUF_H_
SCC common utilities.
Definition bit_field.h:30