File.h (1717B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 4 #pragma once 5 6 #include "Result.h" 7 8 #include <cstdint> 9 #include <memory> 10 #include <string> 11 #include <unordered_map> 12 13 namespace SFS 14 { 15 enum class HashType 16 { 17 Sha1, 18 Sha256 19 }; 20 21 class File 22 { 23 public: 24 [[nodiscard]] static Result Make(std::string fileId, 25 std::string url, 26 uint64_t sizeInBytes, 27 std::unordered_map<HashType, std::string> hashes, 28 std::unique_ptr<File>& out) noexcept; 29 30 File(File&&) noexcept; 31 32 File(const File&) = delete; 33 File& operator=(const File&) = delete; 34 35 /** 36 * @return Unique file identifier within a content version 37 */ 38 const std::string& GetFileId() const noexcept; 39 40 /** 41 * @return Download URL 42 */ 43 const std::string& GetUrl() const noexcept; 44 45 /** 46 * @return File size in number of bytes 47 */ 48 uint64_t GetSizeInBytes() const noexcept; 49 50 /** 51 * @return Dictionary of algorithm type to base64 encoded file hash string 52 */ 53 const std::unordered_map<HashType, std::string>& GetHashes() const noexcept; 54 55 protected: 56 File(std::string&& fileId, 57 std::string&& url, 58 uint64_t sizeInBytes, 59 std::unordered_map<HashType, std::string>&& hashes); 60 61 [[nodiscard]] Result Clone(std::unique_ptr<File>& out) const noexcept; 62 63 friend class Content; 64 65 std::string m_fileId; 66 std::string m_url; 67 uint64_t m_sizeInBytes; 68 std::unordered_map<HashType, std::string> m_hashes; 69 }; 70 } // namespace SFS