block.h 977 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. #include <library/cpp/streams/lz/common/compressor.h>
  3. #include <contrib/libs/snappy/snappy.h>
  4. /*
  5. * Snappy
  6. */
  7. class TSnappy {
  8. public:
  9. static constexpr char signature[] = "Snap";
  10. static inline size_t Hint(size_t len) noexcept {
  11. return Max<size_t>(snappy::MaxCompressedLength(len), 100);
  12. }
  13. inline size_t Compress(const char* data, size_t len, char* ptr, size_t /*dstMaxSize*/) {
  14. size_t reslen = 0;
  15. snappy::RawCompress(data, len, ptr, &reslen);
  16. return reslen;
  17. }
  18. inline size_t Decompress(const char* data, size_t len, char* ptr, size_t) {
  19. size_t srclen = 0;
  20. if (!snappy::GetUncompressedLength(data, len, &srclen) || !snappy::RawUncompress(data, len, ptr))
  21. ythrow TDecompressorError();
  22. return srclen;
  23. }
  24. inline void InitFromStream(IInputStream*) const noexcept {
  25. }
  26. static inline bool SaveIncompressibleChunks() noexcept {
  27. return false;
  28. }
  29. };