Add option for lazy archive creation with MultiPartArchiveWriter
This commit is contained in:
@@ -14,15 +14,16 @@ namespace openVulkanoCpp
|
||||
{
|
||||
MultiPartArchiveWriter::MultiPartArchiveWriter(const std::string& dir, const std::string& fileNamePattern,
|
||||
const ArchiveConfiguration& archiveConfiguration,
|
||||
size_t sizeLimit, const std::shared_ptr<spdlog::logger>& logger)
|
||||
size_t sizeLimit, bool lazyCreation,
|
||||
const std::shared_ptr<spdlog::logger>& logger)
|
||||
: m_fileSizeLimit(sizeLimit), m_archiveId(0), m_archiveConfig(archiveConfiguration)
|
||||
, m_dir(dir), m_fileNamePattern(fileNamePattern), m_logger(logger)
|
||||
, m_dir(dir), m_fileNamePattern(fileNamePattern), m_logger(logger), m_lazyCreation(lazyCreation)
|
||||
{
|
||||
if (!m_dir.empty() && !std::filesystem::exists(m_dir))
|
||||
{
|
||||
std::filesystem::create_directories(m_dir);
|
||||
}
|
||||
StartNewFile();
|
||||
if (!lazyCreation) StartNewFile();
|
||||
}
|
||||
|
||||
MultiPartArchiveWriter::~MultiPartArchiveWriter()
|
||||
@@ -99,12 +100,12 @@ namespace openVulkanoCpp
|
||||
m_archives.clear();
|
||||
}
|
||||
m_dir = newDir;
|
||||
StartNewFile();
|
||||
if (!m_lazyCreation) StartNewFile();
|
||||
}
|
||||
|
||||
void MultiPartArchiveWriter::Split()
|
||||
{
|
||||
if (!m_writer->GetTotalWrittenBytes()) return; // Nothing has been written yet, no need to split file
|
||||
if (!m_writer || !m_writer->GetTotalWrittenBytes()) return; // Nothing has been written yet, no need to split file
|
||||
m_writer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "ArchiveWriter.hpp"
|
||||
#include "Math/ByteSize.hpp"
|
||||
#include <memory>
|
||||
|
||||
namespace openVulkanoCpp
|
||||
@@ -21,13 +22,14 @@ namespace openVulkanoCpp
|
||||
std::unique_ptr<ArchiveWriter> m_writer;
|
||||
std::shared_ptr<spdlog::logger> m_logger;
|
||||
std::vector<std::filesystem::path> m_archives;
|
||||
bool m_lazyCreation;
|
||||
|
||||
void StartNewFile();
|
||||
|
||||
void CheckSize(size_t size);
|
||||
|
||||
public:
|
||||
MultiPartArchiveWriter(const std::string& dir, const std::string& fileNamePattern, const ArchiveConfiguration& archiveConfiguration, size_t sizeLimit = 2ull << 30, const std::shared_ptr<spdlog::logger>& logger = nullptr);
|
||||
MultiPartArchiveWriter(const std::string& dir, const std::string& fileNamePattern, const ArchiveConfiguration& archiveConfiguration, size_t sizeLimit = 2_GiB, bool lazyCreation = false, const std::shared_ptr<spdlog::logger>& logger = nullptr);
|
||||
|
||||
~MultiPartArchiveWriter() override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user