1#pragma once
2
3#include <IO/WriteBufferFromFileBase.h>
4
5
6namespace DB
7{
8
9/** Use ready file descriptor. Does not open or close a file.
10 */
11class WriteBufferFromFileDescriptor : public WriteBufferFromFileBase
12{
13protected:
14 int fd;
15
16 void nextImpl() override;
17
18 /// Name or some description of file.
19 std::string getFileName() const override;
20
21public:
22 WriteBufferFromFileDescriptor(
23 int fd_ = -1,
24 size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE,
25 char * existing_memory = nullptr,
26 size_t alignment = 0);
27
28 /** Could be used before initialization if needed 'fd' was not passed to constructor.
29 * It's not possible to change 'fd' during work.
30 */
31 void setFD(int fd_)
32 {
33 fd = fd_;
34 }
35
36 ~WriteBufferFromFileDescriptor() override;
37
38 int getFD() const override
39 {
40 return fd;
41 }
42
43 off_t getPositionInFile() override;
44
45 void sync() override;
46
47private:
48 off_t doSeek(off_t offset, int whence) override;
49
50 void doTruncate(off_t length) override;
51};
52
53}
54