diff options
Diffstat (limited to 'src/serialization.cpp')
-rw-r--r-- | src/serialization.cpp | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/src/serialization.cpp b/src/serialization.cpp index b6ce3b37f..11164a0ed 100644 --- a/src/serialization.cpp +++ b/src/serialization.cpp @@ -108,7 +108,6 @@ void decompressZlib(std::istream &is, std::ostream &os, size_t limit) char output_buffer[bufsize]; int status = 0; int ret; - int bytes_read = 0; int bytes_written = 0; int input_buffer_len = 0; @@ -122,8 +121,6 @@ void decompressZlib(std::istream &is, std::ostream &os, size_t limit) z.avail_in = 0; - //dstream<<"initial fail="<<is.fail()<<" bad="<<is.bad()<<std::endl; - for(;;) { int output_size = bufsize; @@ -147,19 +144,13 @@ void decompressZlib(std::istream &is, std::ostream &os, size_t limit) is.read(input_buffer, bufsize); input_buffer_len = is.gcount(); z.avail_in = input_buffer_len; - //dstream<<"read fail="<<is.fail()<<" bad="<<is.bad()<<std::endl; } if(z.avail_in == 0) { - //dstream<<"z.avail_in == 0"<<std::endl; break; } - //dstream<<"1 z.avail_in="<<z.avail_in<<std::endl; status = inflate(&z, Z_NO_FLUSH); - //dstream<<"2 z.avail_in="<<z.avail_in<<std::endl; - bytes_read += is.gcount() - z.avail_in; - //dstream<<"bytes_read="<<bytes_read<<std::endl; if(status == Z_NEED_DICT || status == Z_DATA_ERROR || status == Z_MEM_ERROR) @@ -168,16 +159,11 @@ void decompressZlib(std::istream &is, std::ostream &os, size_t limit) throw SerializationError("decompressZlib: inflate failed"); } int count = output_size - z.avail_out; - //dstream<<"count="<<count<<std::endl; if(count) os.write(output_buffer, count); bytes_written += count; if(status == Z_STREAM_END) { - //dstream<<"Z_STREAM_END"<<std::endl; - - //dstream<<"z.avail_in="<<z.avail_in<<std::endl; - //dstream<<"fail="<<is.fail()<<" bad="<<is.bad()<<std::endl; // Unget all the data that inflate didn't take is.clear(); // Just in case EOF is set for(u32 i=0; i < z.avail_in; i++) @@ -211,9 +197,10 @@ struct ZSTD_Deleter { void compressZstd(const u8 *data, size_t data_size, std::ostream &os, int level) { // reusing the context is recommended for performance - // it will destroyed when the thread ends + // it will be destroyed when the thread ends thread_local std::unique_ptr<ZSTD_CStream, ZSTD_Deleter> stream(ZSTD_createCStream()); + ZSTD_initCStream(stream.get(), level); const size_t bufsize = 16384; @@ -257,7 +244,7 @@ void compressZstd(const std::string &data, std::ostream &os, int level) void decompressZstd(std::istream &is, std::ostream &os) { // reusing the context is recommended for performance - // it will destroyed when the thread ends + // it will be destroyed when the thread ends thread_local std::unique_ptr<ZSTD_DStream, ZSTD_Deleter> stream(ZSTD_createDStream()); ZSTD_initDStream(stream.get()); |