winix/core/compress.h

77 lines
1.6 KiB
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2014, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfile_winix_core_compress
#define headerfile_winix_core_compress
#include <cstring>
#include <zlib.h>
#include "requesttypes.h"
namespace Winix
{
class Compress
{
public:
Compress();
~Compress();
int Init(int compress_level_ = 6);
/*
encoding:
0 - raw deflate data with no zlib header or trailer, and will not compute an adler32 check value
(for Internet Explorer)
1 - deflate
2 - gzip
*/
int Compressing(const char * source, size_t source_len, BinaryPage & out_stream, int encoding = 2);
int Compressing(const BinaryPage & in, BinaryPage & out, int encoding = 2);
private:
bool AllocateMemory();
bool InitRawDeflate();
bool InitDeflate();
bool InitGzip();
int MakeCompress(z_stream & strm, const char * source, size_t source_len, BinaryPage & out_stream, int encoding);
int MakeCompress(z_stream & strm, const BinaryPage & page, BinaryPage & out, int encoding);
z_stream * SelectStream(int encoding);
void ResetStream(z_stream * pstrm, int encoding);
void PutLog(size_t source_len, int encoding);
void CopyToInputBuffer(BinaryPage::const_iterator & i, size_t len);
int compress_level;
size_t buffer_max_len;
// size of the last compressed page
size_t last_out_size;
char * buffer_in;
char * buffer_out;
z_stream strm_raw_deflate, strm_deflate, strm_gzip;
bool raw_deflate_inited, deflate_inited, gzip_inited;
bool ready_for_compress;
};
} // namespace Winix
#endif