block.h 858 B

1234567891011121314151617181920212223242526272829303132333435
  1. #pragma once
  2. #include <library/cpp/streams/lz/common/compressor.h>
  3. #include <contrib/libs/lz4/lz4.h>
  4. /*
  5. * LZ4
  6. */
  7. class TLZ4 {
  8. public:
  9. static constexpr char signature[]= "LZ.4";
  10. static inline size_t Hint(size_t len) noexcept {
  11. return Max<size_t>((size_t)(len * 1.06), 100);
  12. }
  13. inline size_t Compress(const char* data, size_t len, char* ptr, size_t dstMaxSize) {
  14. return LZ4_compress_default(data, ptr, len, dstMaxSize);
  15. }
  16. inline size_t Decompress(const char* data, size_t len, char* ptr, size_t max) {
  17. int res = LZ4_decompress_safe(data, ptr, len, max);
  18. if (res < 0)
  19. ythrow TDecompressorError();
  20. return res;
  21. }
  22. inline void InitFromStream(IInputStream*) const noexcept {
  23. }
  24. static inline bool SaveIncompressibleChunks() noexcept {
  25. return false;
  26. }
  27. };