diff options
author | Arseny Smalyuk <smalukav@gmail.com> | 2022-02-10 16:48:05 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:05 +0300 |
commit | 12559cd7f2fa0cf54ffb0d961949fea58c0e18cb (patch) | |
tree | 1c6e1bb383ce1ed8ea168386f913410dd55ccb7f /util/stream | |
parent | 5b8d95df2f0cfca4d3f5499a4259aa2050ef1571 (diff) | |
download | ydb-12559cd7f2fa0cf54ffb0d961949fea58c0e18cb.tar.gz |
Restoring authorship annotation for Arseny Smalyuk <smalukav@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'util/stream')
-rw-r--r-- | util/stream/zlib.cpp | 32 | ||||
-rw-r--r-- | util/stream/zlib_ut.cpp | 180 |
2 files changed, 106 insertions, 106 deletions
diff --git a/util/stream/zlib.cpp b/util/stream/zlib.cpp index 60f4e9439f0..983b753dc23 100644 --- a/util/stream/zlib.cpp +++ b/util/stream/zlib.cpp @@ -267,20 +267,20 @@ public: } inline void Flush() { - int ret = deflate(Z(), Z_SYNC_FLUSH); - - while ((ret == Z_OK || ret == Z_BUF_ERROR) && !Z()->avail_out) { - FlushBuffer(); - ret = deflate(Z(), Z_SYNC_FLUSH); - } - - if (ret != Z_OK && ret != Z_BUF_ERROR) { - ythrow TZLibCompressorError() << "deflate flush error(" << GetErrMsg() << ")"; - } - - if (Z()->avail_out < TmpBufLen()) { - FlushBuffer(); - } + int ret = deflate(Z(), Z_SYNC_FLUSH); + + while ((ret == Z_OK || ret == Z_BUF_ERROR) && !Z()->avail_out) { + FlushBuffer(); + ret = deflate(Z(), Z_SYNC_FLUSH); + } + + if (ret != Z_OK && ret != Z_BUF_ERROR) { + ythrow TZLibCompressorError() << "deflate flush error(" << GetErrMsg() << ")"; + } + + if (Z()->avail_out < TmpBufLen()) { + FlushBuffer(); + } } inline void FlushBuffer() { @@ -300,7 +300,7 @@ public: if (ret == Z_STREAM_END) { Stream_->Write(TmpBuf(), TmpBufLen() - Z()->avail_out); } else { - ythrow TZLibCompressorError() << "deflate finish error(" << GetErrMsg() << ")"; + ythrow TZLibCompressorError() << "deflate finish error(" << GetErrMsg() << ")"; } } @@ -339,7 +339,7 @@ size_t TZLibDecompress::DoRead(void* buf, size_t size) { } void TZLibCompress::Init(const TParams& params) { - Y_ENSURE(params.BufLen >= 16, "ZLib buffer too small"); + Y_ENSURE(params.BufLen >= 16, "ZLib buffer too small"); Impl_.Reset(new (params.BufLen) TImpl(params)); } diff --git a/util/stream/zlib_ut.cpp b/util/stream/zlib_ut.cpp index 2290b4a9dee..a03904fe3df 100644 --- a/util/stream/zlib_ut.cpp +++ b/util/stream/zlib_ut.cpp @@ -52,14 +52,14 @@ private: }; Y_UNIT_TEST_SUITE(TZLibTest) { - static const TString DATA = "8s7d5vc6s5vc67sa4c65ascx6asd4xcv76adsfxv76s"; - static const TString DATA2 = "cn8wk2bd9vb3vdfif83g1ks94bfiovtwv"; + static const TString DATA = "8s7d5vc6s5vc67sa4c65ascx6asd4xcv76adsfxv76s"; + static const TString DATA2 = "cn8wk2bd9vb3vdfif83g1ks94bfiovtwv"; Y_UNIT_TEST(Compress) { TUnbufferedFileOutput o(ZDATA); TZLibCompress c(&o, ZLib::ZLib); - c.Write(DATA.data(), DATA.size()); + c.Write(DATA.data(), DATA.size()); c.Finish(); o.Finish(); } @@ -71,7 +71,7 @@ Y_UNIT_TEST_SUITE(TZLibTest) { TUnbufferedFileInput i(ZDATA); TZLibDecompress d(&i); - UNIT_ASSERT_EQUAL(d.ReadAll(), DATA); + UNIT_ASSERT_EQUAL(d.ReadAll(), DATA); } } @@ -96,10 +96,10 @@ Y_UNIT_TEST_SUITE(TZLibTest) { { TUnbufferedFileOutput o(ZDATA); TZLibCompress c1(&o, ZLib::ZLib); - c1.Write(DATA.data(), DATA.size()); + c1.Write(DATA.data(), DATA.size()); c1.Finish(); TZLibCompress c2(&o, ZLib::ZLib); - c2.Write(DATA2.data(), DATA2.size()); + c2.Write(DATA2.data(), DATA2.size()); c2.Finish(); o.Finish(); } @@ -107,7 +107,7 @@ Y_UNIT_TEST_SUITE(TZLibTest) { TUnbufferedFileInput i(ZDATA); TZLibDecompress d(&i); - UNIT_ASSERT_EQUAL(d.ReadAll(), DATA + DATA2); + UNIT_ASSERT_EQUAL(d.ReadAll(), DATA + DATA2); } } @@ -132,10 +132,10 @@ Y_UNIT_TEST_SUITE(TZLibTest) { { TUnbufferedFileOutput o(ZDATA); TZLibCompress c1(&o, ZLib::ZLib); - c1.Write(DATA.data(), DATA.size()); + c1.Write(DATA.data(), DATA.size()); c1.Finish(); TZLibCompress c2(&o, ZLib::ZLib); - c2.Write(DATA2.data(), DATA2.size()); + c2.Write(DATA2.data(), DATA2.size()); c2.Finish(); o.Finish(); } @@ -144,87 +144,87 @@ Y_UNIT_TEST_SUITE(TZLibTest) { TZLibDecompress d(&i); d.SetAllowMultipleStreams(false); - UNIT_ASSERT_EQUAL(d.ReadAll(), DATA); - } - } - - Y_UNIT_TEST(CompressFlush) { - TString data = ""; - - for (size_t i = 0; i < 32; ++i) { - TTempFile tmpFile(ZDATA); - - TUnbufferedFileOutput output(ZDATA); - TZLibCompress compressor(&output, ZLib::ZLib); - - compressor.Write(data.data(), data.size()); - compressor.Flush(); - - { - TUnbufferedFileInput input(ZDATA); - TZLibDecompress decompressor(&input); - - UNIT_ASSERT_EQUAL(decompressor.ReadAll(), data); - } - - data += 'A' + i; - } - } - - Y_UNIT_TEST(CompressEmptyFlush) { - TTempFile tmpFile(ZDATA); - - TUnbufferedFileOutput output(ZDATA); - TZLibCompress compressor(&output, ZLib::ZLib); - - TUnbufferedFileInput input(ZDATA); - - compressor.Write(DATA.data(), DATA.size()); - compressor.Flush(); - - { - TZLibDecompress decompressor(&input); - UNIT_ASSERT_EQUAL(decompressor.ReadAll(), DATA); - } - - for (size_t i = 0; i < 10; ++i) { - compressor.Flush(); - } - - UNIT_ASSERT_EQUAL(input.ReadAll(), ""); - } - - Y_UNIT_TEST(CompressFlushSmallBuffer) { - for (size_t bufferSize = 16; bufferSize < 32; ++bufferSize) { - TString firstData = ""; - - for (size_t firstDataSize = 0; firstDataSize < 16; ++firstDataSize) { - TString secondData = ""; - - for (size_t secondDataSize = 0; secondDataSize < 16; ++secondDataSize) { - TTempFile tmpFile(ZDATA); - - TUnbufferedFileOutput output(ZDATA); - TZLibCompress compressor(TZLibCompress::TParams(&output).SetType(ZLib::ZLib).SetBufLen(bufferSize)); - - TUnbufferedFileInput input(ZDATA); - TZLibDecompress decompressor(&input); - - compressor.Write(firstData.data(), firstData.size()); - compressor.Flush(); - - UNIT_ASSERT_EQUAL(decompressor.ReadAll(), firstData); - - compressor.Write(secondData.data(), secondData.size()); - compressor.Flush(); - - UNIT_ASSERT_EQUAL(decompressor.ReadAll(), secondData); - - secondData += 'A' + secondDataSize; - } - - firstData += 'A' + firstDataSize; - } + UNIT_ASSERT_EQUAL(d.ReadAll(), DATA); } } + + Y_UNIT_TEST(CompressFlush) { + TString data = ""; + + for (size_t i = 0; i < 32; ++i) { + TTempFile tmpFile(ZDATA); + + TUnbufferedFileOutput output(ZDATA); + TZLibCompress compressor(&output, ZLib::ZLib); + + compressor.Write(data.data(), data.size()); + compressor.Flush(); + + { + TUnbufferedFileInput input(ZDATA); + TZLibDecompress decompressor(&input); + + UNIT_ASSERT_EQUAL(decompressor.ReadAll(), data); + } + + data += 'A' + i; + } + } + + Y_UNIT_TEST(CompressEmptyFlush) { + TTempFile tmpFile(ZDATA); + + TUnbufferedFileOutput output(ZDATA); + TZLibCompress compressor(&output, ZLib::ZLib); + + TUnbufferedFileInput input(ZDATA); + + compressor.Write(DATA.data(), DATA.size()); + compressor.Flush(); + + { + TZLibDecompress decompressor(&input); + UNIT_ASSERT_EQUAL(decompressor.ReadAll(), DATA); + } + + for (size_t i = 0; i < 10; ++i) { + compressor.Flush(); + } + + UNIT_ASSERT_EQUAL(input.ReadAll(), ""); + } + + Y_UNIT_TEST(CompressFlushSmallBuffer) { + for (size_t bufferSize = 16; bufferSize < 32; ++bufferSize) { + TString firstData = ""; + + for (size_t firstDataSize = 0; firstDataSize < 16; ++firstDataSize) { + TString secondData = ""; + + for (size_t secondDataSize = 0; secondDataSize < 16; ++secondDataSize) { + TTempFile tmpFile(ZDATA); + + TUnbufferedFileOutput output(ZDATA); + TZLibCompress compressor(TZLibCompress::TParams(&output).SetType(ZLib::ZLib).SetBufLen(bufferSize)); + + TUnbufferedFileInput input(ZDATA); + TZLibDecompress decompressor(&input); + + compressor.Write(firstData.data(), firstData.size()); + compressor.Flush(); + + UNIT_ASSERT_EQUAL(decompressor.ReadAll(), firstData); + + compressor.Write(secondData.data(), secondData.size()); + compressor.Flush(); + + UNIT_ASSERT_EQUAL(decompressor.ReadAll(), secondData); + + secondData += 'A' + secondDataSize; + } + + firstData += 'A' + firstDataSize; + } + } + } } |