From 2e89a0717a60598904c92499adb7e01b2075fbb9 Mon Sep 17 00:00:00 2001 From: "Emma@Rory&" Date: Wed, 26 Jul 2023 21:02:50 +0200 Subject: MRU desktop start --- MatrixRoomUtils.Desktop/FileStorageProvider.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'MatrixRoomUtils.Desktop/FileStorageProvider.cs') diff --git a/MatrixRoomUtils.Desktop/FileStorageProvider.cs b/MatrixRoomUtils.Desktop/FileStorageProvider.cs index 36025eb..6c44fd2 100644 --- a/MatrixRoomUtils.Desktop/FileStorageProvider.cs +++ b/MatrixRoomUtils.Desktop/FileStorageProvider.cs @@ -3,7 +3,7 @@ using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces.Services; using Microsoft.Extensions.Logging; -namespace MatrixRoomUtils.Desktop; +namespace MatrixRoomUtils.Desktop; public class FileStorageProvider : IStorageProvider { private readonly ILogger _logger; @@ -32,4 +32,11 @@ public class FileStorageProvider : IStorageProvider { public async Task> GetAllKeysAsync() => Directory.GetFiles(TargetPath).Select(Path.GetFileName).ToList(); public async Task DeleteObjectAsync(string key) => File.Delete(Path.Join(TargetPath, key)); -} \ No newline at end of file + public async Task SaveStreamAsync(string key, Stream stream) { + Directory.CreateDirectory(Path.GetDirectoryName(Path.Join(TargetPath, key)) ?? throw new InvalidOperationException()); + await using var fileStream = File.Create(Path.Join(TargetPath, key)); + await stream.CopyToAsync(fileStream); + } + + public async Task LoadStreamAsync(string key) => File.Exists(Path.Join(TargetPath, key)) ? File.OpenRead(Path.Join(TargetPath, key)) : null; +} -- cgit 1.4.1