mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-28 02:21:59 +00:00
40 lines
809 B
C
40 lines
809 B
C
|
#pragma once
|
||
|
|
||
|
#include <fcntl.h>
|
||
|
|
||
|
#include <DB/IO/ReadBufferFromFileDescriptor.h>
|
||
|
|
||
|
|
||
|
namespace DB
|
||
|
{
|
||
|
|
||
|
/** Принимает имя файла. Самостоятельно открывает и закрывает файл.
|
||
|
*/
|
||
|
class ReadBufferFromFile : public ReadBufferFromFileDescriptor
|
||
|
{
|
||
|
private:
|
||
|
std::string file_name;
|
||
|
|
||
|
public:
|
||
|
ReadBufferFromFile(const std::string & file_name_) : ReadBufferFromFileDescriptor(-1), file_name(file_name_)
|
||
|
{
|
||
|
fd = open(file_name.c_str(), O_RDONLY);
|
||
|
|
||
|
if (-1 == fd)
|
||
|
throwFromErrno("Cannot open file " + file_name, ErrorCodes::CANNOT_OPEN_FILE);
|
||
|
}
|
||
|
|
||
|
virtual ~ReadBufferFromFile()
|
||
|
{
|
||
|
if (0 != close(fd))
|
||
|
throwFromErrno("Cannot close file " + file_name, ErrorCodes::CANNOT_CLOSE_FILE);
|
||
|
}
|
||
|
|
||
|
virtual std::string getFileName()
|
||
|
{
|
||
|
return file_name;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
}
|