Botan 1.10.17
Botan::Zlib_Compression Class Reference

#include <zlib.h>

Inheritance diagram for Botan::Zlib_Compression:
Botan::Filter

Public Member Functions

virtual bool attachable ()
void end_msg ()
void flush ()
std::string name () const
void start_msg ()
void write (const byte input[], size_t length)
 Zlib_Compression (size_t level=6)
 ~Zlib_Compression ()

Protected Member Functions

void send (byte in)
void send (const byte in[], size_t length)
void send (const MemoryRegion< byte > &in)
void send (const MemoryRegion< byte > &in, size_t length)

Detailed Description

Zlib Compression Filter

Definition at line 19 of file zlib.h.

Constructor & Destructor Documentation

◆ Zlib_Compression()

Botan::Zlib_Compression::Zlib_Compression ( size_t level = 6)
Parameters
levelhow much effort to use on compressing (0 to 9); higher levels are slower but tend to give better compression

Definition at line 94 of file zlib.cpp.

94 :
95 level((l >= 9) ? 9 : l), buffer(DEFAULT_BUFFERSIZE)
96 {
97 zlib = 0;
98 }

◆ ~Zlib_Compression()

Botan::Zlib_Compression::~Zlib_Compression ( )
inline

Definition at line 39 of file zlib.h.

39{ clear(); }

Member Function Documentation

◆ attachable()

virtual bool Botan::Filter::attachable ( )
inlinevirtualinherited

Check whether this filter is an attachable filter.

Returns
true if this filter is attachable, false otherwise

Reimplemented in Botan::DataSink, and Botan::SecureQueue.

Definition at line 50 of file filter.h.

50{ return true; }

◆ end_msg()

void Botan::Zlib_Compression::end_msg ( )
virtual

Notify that the current message is finished; flush buffers and do end-of-message processing (if any).

Reimplemented from Botan::Filter.

Definition at line 131 of file zlib.cpp.

132 {
133 zlib->stream.next_in = 0;
134 zlib->stream.avail_in = 0;
135
136 int rc = Z_OK;
137 while(rc != Z_STREAM_END)
138 {
139 zlib->stream.next_out = reinterpret_cast<Bytef*>(buffer.begin());
140 zlib->stream.avail_out = buffer.size();
141
142 rc = deflate(&(zlib->stream), Z_FINISH);
143 send(buffer.begin(), buffer.size() - zlib->stream.avail_out);
144 }
145
146 clear();
147 }
void send(const byte in[], size_t length)
Definition filter.cpp:28

References Botan::Filter::send().

◆ flush()

void Botan::Zlib_Compression::flush ( )

Flush the compressor

Definition at line 152 of file zlib.cpp.

153 {
154 zlib->stream.next_in = 0;
155 zlib->stream.avail_in = 0;
156
157 while(true)
158 {
159 zlib->stream.avail_out = buffer.size();
160 zlib->stream.next_out = reinterpret_cast<Bytef*>(buffer.begin());
161
162 deflate(&(zlib->stream), Z_FULL_FLUSH);
163 send(buffer.begin(), buffer.size() - zlib->stream.avail_out);
164
165 if(zlib->stream.avail_out == buffer.size())
166 break;
167 }
168 }

References Botan::Filter::send().

◆ name()

std::string Botan::Zlib_Compression::name ( ) const
inlinevirtual
Returns
descriptive name for this filter

Implements Botan::Filter.

Definition at line 22 of file zlib.h.

22{ return "Zlib_Compression"; }

◆ send() [1/4]

void Botan::Filter::send ( byte in)
inlineprotectedinherited
Parameters
insome input for the filter

Definition at line 63 of file filter.h.

63{ send(&in, 1); }

References send().

Referenced by send().

◆ send() [2/4]

void Botan::Filter::send ( const byte in[],
size_t length )
protectedinherited

◆ send() [3/4]

void Botan::Filter::send ( const MemoryRegion< byte > & in)
inlineprotectedinherited
Parameters
insome input for the filter

Definition at line 68 of file filter.h.

68{ send(&in[0], in.size()); }

References send(), and Botan::MemoryRegion< T >::size().

Referenced by send().

◆ send() [4/4]

void Botan::Filter::send ( const MemoryRegion< byte > & in,
size_t length )
inlineprotectedinherited
Parameters
insome input for the filter
lengththe number of bytes of in to send

Definition at line 74 of file filter.h.

75 {
76 send(&in[0], length);
77 }

References send().

◆ start_msg()

void Botan::Zlib_Compression::start_msg ( )
virtual

Start a new message. Must be closed by end_msg() before another message can be started.

Reimplemented from Botan::Filter.

Definition at line 103 of file zlib.cpp.

104 {
105 clear();
106 zlib = new Zlib_Stream;
107 if(deflateInit(&(zlib->stream), level) != Z_OK)
108 throw Memory_Exhaustion();
109 }

◆ write()

void Botan::Zlib_Compression::write ( const byte input[],
size_t length )
virtual

Write a portion of a message to this filter.

Parameters
inputthe input as a byte array
lengththe length of the byte array input

Implements Botan::Filter.

Definition at line 114 of file zlib.cpp.

115 {
116 zlib->stream.next_in = static_cast<Bytef*>(const_cast<byte*>(input));
117 zlib->stream.avail_in = length;
118
119 while(zlib->stream.avail_in != 0)
120 {
121 zlib->stream.next_out = static_cast<Bytef*>(buffer.begin());
122 zlib->stream.avail_out = buffer.size();
123 deflate(&(zlib->stream), Z_NO_FLUSH);
124 send(buffer.begin(), buffer.size() - zlib->stream.avail_out);
125 }
126 }

References Botan::Filter::send().


The documentation for this class was generated from the following files: