join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
zstream.hpp
Go to the documentation of this file.
1
25#ifndef __JOIN_ZSTREAM_HPP__
26#define __JOIN_ZSTREAM_HPP__
27
28// libjoin.
29#include <join/streambuf.hpp>
30
31// Libraries.
32#include <zlib.h>
33
34namespace join
35{
40 {
41 public:
48 Zstreambuf (std::streambuf* streambuf, int format, bool own = false);
49
54 Zstreambuf (const Zstreambuf& other) = delete;
55
61 Zstreambuf& operator= (const Zstreambuf& other) = delete;
62
67 Zstreambuf (Zstreambuf&& other);
68
75
79 virtual ~Zstreambuf ();
80
81 protected:
86 virtual int_type underflow () override;
87
93 virtual int_type overflow (int_type c = traits_type::eof ()) override;
94
99 virtual int_type sync () override;
100
102 static const std::streamsize _bufsize = 16384;
103
105 std::unique_ptr <z_stream> _inflate;
106
108 int _instate = Z_OK;
109
111 std::unique_ptr <z_stream> _deflate;
112
114 std::unique_ptr <char []> _buf;
115 };
116
120 class Zstream : public std::iostream
121 {
122 public:
127 {
128 Deflate = -MAX_WBITS,
129 Zlib = MAX_WBITS,
130 Gzip = MAX_WBITS + 16,
131 };
132
138 Zstream (std::iostream& stream, Format format = Zlib);
139
144 Zstream (const Zstream& other) = delete;
145
151 Zstream& operator=(const Zstream& other) = delete;
152
157 Zstream (Zstream&& other);
158
164 Zstream& operator=(Zstream&& other);
165
169 virtual ~Zstream () = default;
170
171 protected:
174 };
175}
176
177#endif
stream buffer decorator.
Definition streambuf.hpp:38
zlib stream.
Definition zstream.hpp:121
Format
data format.
Definition zstream.hpp:127
@ Zlib
Definition zstream.hpp:129
@ Deflate
Definition zstream.hpp:128
@ Gzip
Definition zstream.hpp:130
Zstream(const Zstream &other)=delete
copy constructor.
Zstream(std::iostream &stream, Format format=Zlib)
create the zlib stream instance.
Definition zstream.cpp:200
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:173
zlib stream buffer.
Definition zstream.hpp:40
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:95
Zstreambuf(std::streambuf *streambuf, int format, bool own=false)
create the zlib stream buffer instance.
Definition zstream.cpp:36
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:139
int _instate
inflate state.
Definition zstream.hpp:108
std::unique_ptr< z_stream > _inflate
inflate context.
Definition zstream.hpp:105
static const std::streamsize _bufsize
internal buffer size.
Definition zstream.hpp:102
Zstreambuf(const Zstreambuf &other)=delete
copy constructor.
virtual ~Zstreambuf()
destroy the zlib stream buffer instance.
Definition zstream.cpp:75
std::unique_ptr< char[]> _buf
internal buffer.
Definition zstream.hpp:114
virtual int_type sync() override
synchronizes the buffers with the associated character sequence.
Definition zstream.cpp:186
std::unique_ptr< z_stream > _deflate
deflate context.
Definition zstream.hpp:111
Definition acceptor.hpp:32