ClickHouse/src/Backups/BackupEntryFromSmallFile.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.7 KiB
C++
Raw Normal View History

2021-08-18 22:19:14 +00:00
#include <Backups/BackupEntryFromSmallFile.h>
#include <Common/filesystemHelpers.h>
#include <Disks/DiskLocal.h>
2021-08-18 22:19:14 +00:00
#include <Disks/IDisk.h>
2022-03-08 17:05:55 +00:00
#include <Disks/IO/createReadBufferFromFileBase.h>
#include <IO/ReadBufferFromString.h>
2021-08-18 22:19:14 +00:00
#include <IO/ReadHelpers.h>
namespace DB
{
namespace
{
String readFile(const String & file_path, const ReadSettings & read_settings)
2021-08-18 22:19:14 +00:00
{
auto buf = createReadBufferFromFileBase(file_path, read_settings);
2021-08-18 22:19:14 +00:00
String s;
readStringUntilEOF(s, *buf);
return s;
}
String readFile(const DiskPtr & disk, const String & file_path, const ReadSettings & read_settings, bool copy_encrypted)
2021-08-18 22:19:14 +00:00
{
auto buf = copy_encrypted ? disk->readEncryptedFile(file_path, read_settings) : disk->readFile(file_path, read_settings);
2021-08-18 22:19:14 +00:00
String s;
readStringUntilEOF(s, *buf);
return s;
}
}
BackupEntryFromSmallFile::BackupEntryFromSmallFile(const String & file_path_, const ReadSettings & read_settings_)
: file_path(file_path_)
, data_source_description(DiskLocal::getLocalDataSourceDescription(file_path_))
, data(readFile(file_path_, read_settings_))
2021-08-18 22:19:14 +00:00
{
}
BackupEntryFromSmallFile::BackupEntryFromSmallFile(const DiskPtr & disk_, const String & file_path_, const ReadSettings & read_settings_, bool copy_encrypted_)
: disk(disk_)
, file_path(file_path_)
, data_source_description(disk_->getDataSourceDescription())
, copy_encrypted(copy_encrypted_ && data_source_description.is_encrypted)
, data(readFile(disk_, file_path, read_settings_, copy_encrypted))
{
}
std::unique_ptr<SeekableReadBuffer> BackupEntryFromSmallFile::getReadBuffer(const ReadSettings &) const
2021-08-18 22:19:14 +00:00
{
return std::make_unique<ReadBufferFromString>(data);
2021-08-18 22:19:14 +00:00
}
2022-08-19 14:58:30 +00:00
2021-08-18 22:19:14 +00:00
}