Browse Source

uncompress stream by chunks

pull/386/head
orignal 9 years ago
parent
commit
76b49f6985
  1. 11
      Base.cpp
  2. 3
      Base.h

11
Base.cpp

@ -329,10 +329,15 @@ namespace data @@ -329,10 +329,15 @@ namespace data
return ret == Z_STREAM_END || ret < 0;
}
void GzipInflator::Inflate (std::stringstream& in, std::ostream& out)
void GzipInflator::Inflate (std::istream& in, std::ostream& out)
{
auto str = in.str ().substr (in.tellg ());
Inflate ((const uint8_t *)str.c_str (), str.length (), out);
uint8_t * buf = new uint8_t[GZIP_CHUNK_SIZE];
while (!in.eof ())
{
in.read ((char *)buf, GZIP_CHUNK_SIZE);
Inflate (buf, in.gcount (), out);
}
delete[] buf;
}
GzipDeflator::GzipDeflator (): m_IsDirty (false)

3
Base.h

@ -6,7 +6,6 @@ @@ -6,7 +6,6 @@
#include <string>
#include <zlib.h>
#include <iostream>
#include <sstream>
namespace i2p
{
@ -105,7 +104,7 @@ namespace data @@ -105,7 +104,7 @@ namespace data
size_t Inflate (const uint8_t * in, size_t inLen, uint8_t * out, size_t outLen);
bool Inflate (const uint8_t * in, size_t inLen, std::ostream& s);
// return true when finshed or error, s failbit will be set in case of error
void Inflate (std::stringstream& in, std::ostream& out);
void Inflate (std::istream& in, std::ostream& out);
private:

Loading…
Cancel
Save