private static async Task <int> OnDownload(DownloadOptions options) { // Check if file exist if no ForceOverWrite present. if (!options.ForceOverwrite && File.Exists(options.OutputFile)) { Console.Error.WriteLine($"OutFile {options.OutputFile} already exist, pass in ForceOverwrite if you would like to overwrite"); return(-1); } Console.WriteLine( $"Download global storage blob list for scid : {options.ServiceConfigurationId}, sandbox {options.Sandbox}, path {options.Path}, type {options.Type}"); byte[] blobData = await TitleStorage.DownloadGlobalStorageBlobAsync( options.ServiceConfigurationId, options.Sandbox, options.Path, (TitleStorageBlobType)options.Type); File.WriteAllBytes(options.OutputFile, blobData); Console.WriteLine($"Global storage blob saved as {options.OutputFile}."); return(0); }
public async Task DownloadBlob() { this.SetUpMockAuth(); this.SetupMockBytes(); var uri = new Uri(new Uri(ClientSettings.Singleton.TitleStorageEndpoint), $"global/scids/{DefaultScid}/data/{DefaultGlobalStoragePath},{DefaultFileType}"); var mockHttp = new MockHttpMessageHandler(); Stream stream = new MemoryStream(this.defaultBytes); mockHttp.Expect(HttpMethod.Get, uri.ToString()) .WithHeaders("Authorization", this.ExpectedToken(DefaultScid, DefaultSandbox)) .Respond("application/json", stream); TestHook.MockHttpHandler = mockHttp; TitleStorageBlobType fileType = (TitleStorageBlobType)Enum.Parse(typeof(TitleStorageBlobType), DefaultFileType, true); byte[] bytes = await TitleStorage.DownloadGlobalStorageBlobAsync(DefaultScid, DefaultSandbox, DefaultGlobalStoragePath, fileType); Assert.AreEqual(bytes.Length, this.defaultBytes.Length); }