HttpRandomAccessStream.h (2046B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 4 #pragma once 5 #include "HttpClientWrapper.h" 6 #include "HttpLocalCache.h" 7 8 using namespace std::chrono_literals; 9 10 namespace AppInstaller::Utility::HttpStream 11 { 12 // Provides an implementation of a random access stream over HTTP that supports 13 // range-based fetching. This is intended to be used by AppxPackageReader. 14 // 15 // Note: If the server doesn't support HTTP ranges, this implementation will throw an exception. 16 class HttpRandomAccessStream : public winrt::implements< 17 HttpRandomAccessStream, 18 winrt::Windows::Storage::Streams::IRandomAccessStream, 19 winrt::Windows::Storage::Streams::IInputStream> 20 { 21 public: 22 winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Storage::Streams::IRandomAccessStream> InitializeAsync(const winrt::Windows::Foundation::Uri& uri); 23 uint64_t Size() const; 24 void Size(uint64_t value); 25 uint64_t Position() const; 26 bool CanRead() const; 27 bool CanWrite() const; 28 winrt::Windows::Storage::Streams::IInputStream GetInputStreamAt(uint64_t position) const; 29 winrt::Windows::Storage::Streams::IOutputStream GetOutputStreamAt(uint64_t position) const; 30 winrt::Windows::Storage::Streams::IRandomAccessStream CloneStream() const; 31 void Seek(uint64_t position); 32 winrt::Windows::Foundation::IAsyncOperationWithProgress<winrt::Windows::Storage::Streams::IBuffer, uint32_t> ReadAsync( 33 winrt::Windows::Storage::Streams::IBuffer buffer, 34 uint32_t count, 35 winrt::Windows::Storage::Streams::InputStreamOptions options); 36 std::chrono::seconds RetryAfter() const; 37 38 private: 39 std::shared_ptr<HttpClientWrapper> m_httpHelper; 40 std::unique_ptr<HttpLocalCache> m_httpLocalCache; 41 unsigned long long m_size = 0; 42 unsigned long long m_requestedPosition = 0; 43 std::chrono::seconds m_retryAfter = 0s; 44 }; 45 }