compression.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "compression.h"
  2. #if defined(ENABLE_GPL)
  3. #include <library/cpp/streams/lz/lz.h>
  4. #endif
  5. #include <library/cpp/streams/brotli/brotli.h>
  6. #include <library/cpp/streams/lzma/lzma.h>
  7. #include <library/cpp/streams/bzip2/bzip2.h>
  8. #include <library/cpp/blockcodecs/stream.h>
  9. #include <library/cpp/blockcodecs/codecs.h>
  10. #include <util/stream/zlib.h>
  11. TCompressionCodecFactory::TCompressionCodecFactory() {
  12. auto gzip = [](auto s) {
  13. return MakeHolder<TZLibDecompress>(s);
  14. };
  15. Add("gzip", gzip, [](auto s) { return MakeHolder<TZLibCompress>(s, ZLib::GZip); });
  16. Add("deflate", gzip, [](auto s) { return MakeHolder<TZLibCompress>(s, ZLib::ZLib); });
  17. Add("br", [](auto s) { return MakeHolder<TBrotliDecompress>(s); }, [](auto s) { return MakeHolder<TBrotliCompress>(s, 4); });
  18. Add("x-gzip", gzip, [](auto s) { return MakeHolder<TZLibCompress>(s, ZLib::GZip); });
  19. Add("x-deflate", gzip, [](auto s) { return MakeHolder<TZLibCompress>(s, ZLib::ZLib); });
  20. #if defined(ENABLE_GPL)
  21. const ui16 bs = 32 * 1024;
  22. Add("y-lzo", [](auto s) { return MakeHolder<TLzoDecompress>(s); }, [bs](auto s) { return MakeHolder<TLazy<TLzoCompress> >(s, bs); });
  23. Add("y-lzf", [](auto s) { return MakeHolder<TLzfDecompress>(s); }, [bs](auto s) { return MakeHolder<TLazy<TLzfCompress> >(s, bs); });
  24. Add("y-lzq", [](auto s) { return MakeHolder<TLzqDecompress>(s); }, [bs](auto s) { return MakeHolder<TLazy<TLzqCompress> >(s, bs); });
  25. #endif
  26. Add("y-bzip2", [](auto s) { return MakeHolder<TBZipDecompress>(s); }, [](auto s) { return MakeHolder<TBZipCompress>(s); });
  27. Add("y-lzma", [](auto s) { return MakeHolder<TLzmaDecompress>(s); }, [](auto s) { return MakeHolder<TLzmaCompress>(s); });
  28. for (auto codecName : NBlockCodecs::ListAllCodecs()) {
  29. if (codecName.StartsWith("zstd06")) {
  30. continue;
  31. }
  32. if (codecName.StartsWith("zstd08")) {
  33. continue;
  34. }
  35. auto codec = NBlockCodecs::Codec(codecName);
  36. auto enc = [codec](auto s) {
  37. return MakeHolder<NBlockCodecs::TCodedOutput>(s, codec, 32 * 1024);
  38. };
  39. auto dec = [codec](auto s) {
  40. return MakeHolder<NBlockCodecs::TDecodedInput>(s, codec);
  41. };
  42. Add(TString("z-") + codecName, dec, enc);
  43. }
  44. }
  45. void TCompressionCodecFactory::Add(TStringBuf name, TDecoderConstructor d, TEncoderConstructor e) {
  46. Strings_.emplace_back(name);
  47. Codecs_[Strings_.back()] = TCodec{d, e};
  48. BestCodecs_.emplace_back(Strings_.back());
  49. }