2020-05-22 13:18:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-2020, The PurpleI2P Project
|
|
|
|
*
|
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3
|
|
|
|
*
|
|
|
|
* See full license text in LICENSE file at top of project tree
|
|
|
|
*/
|
|
|
|
|
2016-06-28 00:00:00 +00:00
|
|
|
#ifndef GZIP_H__
|
|
|
|
#define GZIP_H__
|
|
|
|
|
|
|
|
#include <zlib.h>
|
2020-05-17 20:49:31 +00:00
|
|
|
#include <vector>
|
2016-06-28 00:00:00 +00:00
|
|
|
|
2020-03-01 10:25:50 +00:00
|
|
|
namespace i2p
|
2020-05-03 01:18:44 +00:00
|
|
|
{
|
2020-03-01 10:25:50 +00:00
|
|
|
namespace data
|
2020-05-03 01:18:44 +00:00
|
|
|
{
|
2016-06-28 00:00:00 +00:00
|
|
|
class GzipInflator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
GzipInflator ();
|
|
|
|
~GzipInflator ();
|
|
|
|
|
|
|
|
size_t Inflate (const uint8_t * in, size_t inLen, uint8_t * out, size_t outLen);
|
|
|
|
/** @note @a os failbit will be set in case of error */
|
|
|
|
void Inflate (const uint8_t * in, size_t inLen, std::ostream& os);
|
|
|
|
void Inflate (std::istream& in, std::ostream& out);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
z_stream m_Inflator;
|
|
|
|
bool m_IsDirty;
|
|
|
|
};
|
|
|
|
|
|
|
|
class GzipDeflator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
GzipDeflator ();
|
|
|
|
~GzipDeflator ();
|
|
|
|
|
|
|
|
void SetCompressionLevel (int level);
|
|
|
|
size_t Deflate (const uint8_t * in, size_t inLen, uint8_t * out, size_t outLen);
|
2020-05-17 20:49:31 +00:00
|
|
|
size_t Deflate (const std::vector<std::pair<const uint8_t *, size_t> >& bufs, uint8_t * out, size_t outLen);
|
2016-06-28 00:00:00 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
z_stream m_Deflator;
|
|
|
|
bool m_IsDirty;
|
|
|
|
};
|
2020-05-03 01:18:44 +00:00
|
|
|
|
|
|
|
size_t GzipNoCompression (const uint8_t * in, uint16_t inLen, uint8_t * out, size_t outLen); // for < 64K
|
2020-05-20 01:02:32 +00:00
|
|
|
size_t GzipNoCompression (const std::vector<std::pair<const uint8_t *, size_t> >& bufs, uint8_t * out, size_t outLen); // for total size < 64K
|
2016-06-28 00:00:00 +00:00
|
|
|
} // data
|
|
|
|
} // i2p
|
|
|
|
|
|
|
|
#endif /* GZIP_H__ */
|