aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/streams/lz/lz4/block.h
blob: 9a912c0be207c391b11b16555ff2401027977ef3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#pragma once

#include <library/cpp/streams/lz/common/compressor.h>

#include <contrib/libs/lz4/lz4.h>

/*
 * LZ4
 */
class TLZ4 {
public:
    static constexpr char signature[]= "LZ.4";

    static inline size_t Hint(size_t len) noexcept {
        return Max<size_t>((size_t)(len * 1.06), 100);
    }

    inline size_t Compress(const char* data, size_t len, char* ptr, size_t dstMaxSize) {
        return LZ4_compress_default(data, ptr, len, dstMaxSize);
    }

    inline size_t Decompress(const char* data, size_t len, char* ptr, size_t max) {
        int res = LZ4_decompress_safe(data, ptr, len, max);
        if (res < 0)
            ythrow TDecompressorError();
        return res;
    }

    inline void InitFromStream(IInputStream*) const noexcept {
    }

    static inline bool SaveIncompressibleChunks() noexcept {
        return false;
    }
};