aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/streams/xz/decompress.h
blob: 8389cbdaf915247eb85c9b89a5ac59f01d6d3813 (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
36
37
38
39
40
#pragma once

#include <util/stream/buffered.h>
#include <util/stream/input.h>

class IZeroCopyInput;

/**
 * Unbuffered decompressing stream for .XZ and .LZMA files.
 *
 * Do not use it for reading in small pieces.
 */
class TUnbufferedXzDecompress: public IInputStream {
public:
    TUnbufferedXzDecompress(IInputStream* slave);
    TUnbufferedXzDecompress(IZeroCopyInput* slave);
    ~TUnbufferedXzDecompress() override;

private:
    size_t DoRead(void* buf, size_t len) override;

private:
    class TImpl;
    std::unique_ptr<TImpl> Impl_;
};

/**
 * Buffered decompressing stream for .XZ and .LZMA files.
 *
 * Supports efficient `ReadLine` calls and similar "reading in small pieces"
 * usage patterns.
 */
class TXzDecompress: public TBuffered<TUnbufferedXzDecompress> {
public:
    template <class T>
    inline TXzDecompress(T&& t, size_t buf = 1 << 13)
        : TBuffered<TUnbufferedXzDecompress>(buf, std::forward<T>(t))
    {
    }
};