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:
|
2017-04-01 07:20:54 +00:00
|
|
|
using Ptr = std::shared_ptr<WriteBufferFromTemporaryFile>;
|
2017-02-22 15:29:43 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
static Ptr create(const std::string & tmp_dir);
|
2017-02-22 15:29:43 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
~WriteBufferFromTemporaryFile() override;
|
2017-02-22 15:29:43 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2019-10-01 18:51:33 +00:00
|
|
|
WriteBufferFromTemporaryFile(std::unique_ptr<TemporaryFile> && tmp_file);
|
2017-03-27 12:40:08 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::shared_ptr<ReadBuffer> getReadBufferImpl() override;
|
2017-02-28 14:15:13 +00:00
|
|
|
|
2017-03-27 12:40:08 +00:00
|
|
|
protected:
|
|
|
|
|
2019-10-01 18:51:33 +00:00
|
|
|
std::unique_ptr<TemporaryFile> tmp_file;
|
2017-03-27 12:40:08 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
friend class ReadBufferFromTemporaryWriteBuffer;
|
2017-02-22 15:29:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|