2017-02-22 15:29:43 +00:00
|
|
|
#include <DB/IO/WriteBuffer.h>
|
|
|
|
#include <DB/IO/IReadableWriteBuffer.h>
|
|
|
|
#include <DB/IO/WriteBufferFromFile.h>
|
2017-03-27 12:40:08 +00:00
|
|
|
#include <Poco/TemporaryFile.h>
|
|
|
|
|
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:
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
WriteBufferFromTemporaryFile(std::unique_ptr<Poco::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:
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::unique_ptr<Poco::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
|
|
|
};
|
|
|
|
|
|
|
|
}
|