From 0f87d4fb45d27e3f169de99bd4196ebc6eca5e33 Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Tue, 25 Feb 2025 15:18:44 +0100 Subject: ArtifactBlob: Support construction from an existing file --- src/buildtool/common/artifact_blob.hpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/buildtool/common/artifact_blob.hpp') diff --git a/src/buildtool/common/artifact_blob.hpp b/src/buildtool/common/artifact_blob.hpp index c5a03cf9..092dd2b1 100644 --- a/src/buildtool/common/artifact_blob.hpp +++ b/src/buildtool/common/artifact_blob.hpp @@ -16,6 +16,7 @@ #define INCLUDED_SRC_BUILDTOOL_COMMON_ARTIFACT_BLOB_HPP #include +#include #include #include #include @@ -41,6 +42,18 @@ class ArtifactBlob final { std::string content) noexcept -> expected; + /// \brief Create ArtifactBlob based on the existing file. The content is + /// hashed based on the given hash function and ObjectType. + /// \param hash_function Hash function that must be used for hashing. + /// \param type Type of the content. + /// \param file Existing file to be used as the source of + /// content. + /// \return Valid ArtifactBlob on success or an error message on failure. + [[nodiscard]] static auto FromFile(HashFunction hash_function, + ObjectType type, + std::filesystem::path file) noexcept + -> expected; + [[nodiscard]] auto operator==(ArtifactBlob const& other) const noexcept -> bool { return digest_ == other.digest_ and @@ -57,7 +70,8 @@ class ArtifactBlob final { return digest_.size(); } - /// \brief Read the content from source. + /// \brief Read the content from source. This operation may result in the + /// entire file being read into memory. [[nodiscard]] auto ReadContent() const noexcept -> std::shared_ptr; @@ -81,7 +95,8 @@ class ArtifactBlob final { private: using InMemory = std::shared_ptr; - using ContentSource = std::variant; + using InFile = std::filesystem::path; + using ContentSource = std::variant; ArtifactDigest digest_; ContentSource content_; -- cgit v1.2.3