mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
handle compressed addressbook
This commit is contained in:
parent
b4e324ec0e
commit
9a6d478eb1
5 changed files with 64 additions and 4 deletions
32
Base.cpp
32
Base.cpp
|
@ -302,6 +302,38 @@ namespace data
|
|||
}
|
||||
}
|
||||
|
||||
bool GzipInflator::Inflate (const uint8_t * in, size_t inLen, std::ostream& s)
|
||||
{
|
||||
m_IsDirty = true;
|
||||
uint8_t * out = new uint8_t[GZIP_CHUNK_SIZE];
|
||||
m_Inflator.next_in = const_cast<uint8_t *>(in);
|
||||
m_Inflator.avail_in = inLen;
|
||||
int ret;
|
||||
do
|
||||
{
|
||||
m_Inflator.next_out = out;
|
||||
m_Inflator.avail_out = GZIP_CHUNK_SIZE;
|
||||
ret = inflate (&m_Inflator, Z_NO_FLUSH);
|
||||
if (ret < 0)
|
||||
{
|
||||
LogPrint (eLogError, "Decompression error ", ret);
|
||||
inflateEnd (&m_Inflator);
|
||||
s.setstate(std::ios_base::failbit);
|
||||
break;
|
||||
}
|
||||
else
|
||||
s.write ((char *)out, GZIP_CHUNK_SIZE - m_Inflator.avail_out);
|
||||
}
|
||||
while (!m_Inflator.avail_out); // more data to read
|
||||
delete[] out;
|
||||
return ret == Z_STREAM_END || ret < 0;
|
||||
}
|
||||
|
||||
void GzipInflator::Inflate (const std::stringstream& in, std::ostream& out)
|
||||
{
|
||||
Inflate ((const uint8_t *)in.str ().c_str (), in.str ().length (), out);
|
||||
}
|
||||
|
||||
GzipDeflator::GzipDeflator (): m_IsDirty (false)
|
||||
{
|
||||
memset (&m_Deflator, 0, sizeof (m_Deflator));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue