aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/IO/StdIStreamFromMemory.h
blob: 64b147fd29655a57e4b5f024d7bf9f039a9d8fb8 (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
#pragma once

#include <iostream>

namespace DB
{

/// StdIStreamFromMemory is used in WriteBufferFromS3 as a stream which is passed to the S3::Client
/// It provides istream interface (only reading) over the memory.
/// However S3::Client requires iostream interface it only reads from the stream

class StdIStreamFromMemory : public std::iostream
{
    struct MemoryBuf: std::streambuf
    {
            MemoryBuf(char * begin_, size_t size_);

            int_type underflow() override;

            pos_type seekoff(off_type off, std::ios_base::seekdir way,
                             std::ios_base::openmode mode) override;

            pos_type seekpos(pos_type sp,
                             std::ios_base::openmode mode) override;

            char * begin = nullptr;
            size_t size = 0;
    };

    MemoryBuf mem_buf;

public:
    StdIStreamFromMemory(char * begin_, size_t size_);
};

}