2020-10-10 18:37:02 +00:00
|
|
|
#pragma once
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/WriteBuffer.h>
|
|
|
|
#include <IO/IReadableWriteBuffer.h>
|
|
|
|
#include <IO/WriteBufferFromFile.h>
|
2019-10-01 18:51:33 +00:00
|
|
|
#include <Common/filesystemHelpers.h>
|
2017-03-27 12:40:08 +00:00
|
|
|
|
2017-02-22 15:29:43 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Rereadable WriteBuffer, could be used as disk buffer
|
|
|
|
/// Creates unique temporary in directory (and directory itself)
|
|
|
|
class WriteBufferFromTemporaryFile : public WriteBufferFromFile, public IReadableWriteBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using Ptr = std::shared_ptr<WriteBufferFromTemporaryFile>;
|
|
|
|
|
2017-03-27 12:40:08 +00:00
|
|
|
static Ptr create(const std::string & tmp_dir);
|
2017-02-22 15:29:43 +00:00
|
|
|
|
|
|
|
~WriteBufferFromTemporaryFile() override;
|
|
|
|
|
2021-11-10 22:58:56 +00:00
|
|
|
private:
|
2022-03-13 11:59:20 +00:00
|
|
|
explicit WriteBufferFromTemporaryFile(std::unique_ptr<TemporaryFile> && tmp_file);
|
2017-03-27 12:40:08 +00:00
|
|
|
|
2017-02-28 14:15:13 +00:00
|
|
|
std::shared_ptr<ReadBuffer> getReadBufferImpl() override;
|
|
|
|
|
2019-10-01 18:51:33 +00:00
|
|
|
std::unique_ptr<TemporaryFile> tmp_file;
|
2017-03-27 12:40:08 +00:00
|
|
|
|
|
|
|
friend class ReadBufferFromTemporaryWriteBuffer;
|
2017-02-22 15:29:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|