join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
zstream.hpp
Go to the documentation of this file.
1
25#ifndef JOIN_DATA_ZSTREAM_HPP
26#define JOIN_DATA_ZSTREAM_HPP
27
28// libjoin.
29#include <join/streambuf.hpp>
30
31// Libraries.
32#include <zlib.h>
33
34// C++.
35#include <iostream>
36#include <memory>
37
38namespace join
39{
44 {
45 public:
52 Zstreambuf (std::streambuf* streambuf, int format, bool own = false);
53
58 Zstreambuf (const Zstreambuf& other) = delete;
59
65 Zstreambuf& operator= (const Zstreambuf& other) = delete;
66
71 Zstreambuf (Zstreambuf&& other);
72
79
83 virtual ~Zstreambuf ();
84
85 protected:
90 virtual int_type underflow () override;
91
97 virtual int_type overflow (int_type c = traits_type::eof ()) override;
98
103 virtual int_type sync () override;
104
108 void release ();
109
111 static const std::streamsize _bufsize = 16384;
112
114 std::unique_ptr<z_stream> _inflate;
115
117 int _instate = Z_OK;
118
120 std::unique_ptr<z_stream> _deflate;
121
123 std::unique_ptr<char[]> _buf;
124 };
125
129 class Zstream : public std::iostream
130 {
131 public:
136 {
137 Deflate = -MAX_WBITS,
138 Zlib = MAX_WBITS,
139 Gzip = MAX_WBITS + 16,
140 };
141
147 Zstream (std::iostream& stream, Format format = Zlib);
148
153 Zstream (const Zstream& other) = delete;
154
160 Zstream& operator= (const Zstream& other) = delete;
161
166 Zstream (Zstream&& other);
167
173 Zstream& operator= (Zstream&& other);
174
178 virtual ~Zstream () = default;
179
180 protected:
183 };
184}
185
186#endif
stream buffer decorator.
Definition streambuf.hpp:38
zlib stream.
Definition zstream.hpp:130
Format
data format.
Definition zstream.hpp:136
@ Zlib
Definition zstream.hpp:138
@ Deflate
Definition zstream.hpp:137
@ Gzip
Definition zstream.hpp:139
Zstream(const Zstream &other)=delete
copy constructor.
Zstream(std::iostream &stream, Format format=Zlib)
create the zlib stream instance.
Definition zstream.cpp:213
virtual ~Zstream()=default
destroy the zlib stream instance.
Zstream & operator=(const Zstream &other)=delete
copy assignment operator.
Zstreambuf _zbuf
zlib stream buffer
Definition zstream.hpp:182
zlib stream buffer.
Definition zstream.hpp:44
void release()
flush pending output and release the zlib contexts.
Definition zstream.cpp:88
Zstreambuf & operator=(const Zstreambuf &other)=delete
copy assignment operator.
virtual int_type underflow() override
reads characters from the associated input sequence to the get area.
Definition zstream.cpp:108
Zstreambuf(std::streambuf *streambuf, int format, bool own=false)
create the zlib stream buffer instance.
Definition zstream.cpp:39
std::unique_ptr< char[]> _buf
internal buffer.
Definition zstream.hpp:123
virtual int_type overflow(int_type c=traits_type::eof()) override
writes characters to the associated output sequence from the put area.
Definition zstream.cpp:152
int _instate
inflate state.
Definition zstream.hpp:117
std::unique_ptr< z_stream > _inflate
inflate context.
Definition zstream.hpp:114
static const std::streamsize _bufsize
internal buffer size.
Definition zstream.hpp:111
Zstreambuf(const Zstreambuf &other)=delete
copy constructor.
virtual ~Zstreambuf()
destroy the zlib stream buffer instance.
Definition zstream.cpp:79
virtual int_type sync() override
synchronizes the buffers with the associated character sequence.
Definition zstream.cpp:199
std::unique_ptr< z_stream > _deflate
deflate context.
Definition zstream.hpp:120
Definition acceptor.hpp:32