#include #include #include #include using namespace NBlockCodecs; namespace { struct TZLibCodec: public TAddLengthCodec { inline TZLibCodec(int level) : MyName("zlib-" + ToString(level)) , Level(level) { } static inline size_t DoMaxCompressedLength(size_t in) noexcept { return compressBound(in); } TStringBuf Name() const noexcept override { return MyName; } inline size_t DoCompress(const TData& in, void* buf) const { //TRASH detected uLong ret = Max(); int cres = compress2((Bytef*)buf, &ret, (const Bytef*)in.data(), in.size(), Level); if (cres != Z_OK) { ythrow TCompressError(cres); } return ret; } inline void DoDecompress(const TData& in, void* out, size_t len) const { uLong ret = len; int uncres = uncompress((Bytef*)out, &ret, (const Bytef*)in.data(), in.size()); if (uncres != Z_OK) { ythrow TDecompressError(uncres); } if (ret != len) { ythrow TDecompressError(len, ret); } } const TString MyName; const int Level; }; struct TZLibRegistrar { TZLibRegistrar() { for (int i = 0; i < 10; ++i) { RegisterCodec(MakeHolder(i)); } RegisterAlias("zlib", "zlib-6"); } }; const TZLibRegistrar Registrar{}; }