about summary refs log tree commit diff
path: root/MatrixRoomUtils.Desktop/FileStorageProvider.cs
diff options
context:
space:
mode:
authorEmma@Rory& <root@rory.gay>2023-07-26 21:02:50 +0200
committerEmma@Rory& <root@rory.gay>2023-07-26 21:02:50 +0200
commit2e89a0717a60598904c92499adb7e01b2075fbb9 (patch)
tree56b9b7f07180154d9d98dafa91d7c16a0a872100 /MatrixRoomUtils.Desktop/FileStorageProvider.cs
parentStart of nix flake (diff)
downloadMatrixUtils-2e89a0717a60598904c92499adb7e01b2075fbb9.tar.xz
MRU desktop start
Diffstat (limited to 'MatrixRoomUtils.Desktop/FileStorageProvider.cs')
-rw-r--r--MatrixRoomUtils.Desktop/FileStorageProvider.cs11
1 files changed, 9 insertions, 2 deletions
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<FileStorageProvider> _logger;
@@ -32,4 +32,11 @@ public class FileStorageProvider : IStorageProvider {
     public async Task<List<string>> 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<Stream?> LoadStreamAsync(string key) => File.Exists(Path.Join(TargetPath, key)) ? File.OpenRead(Path.Join(TargetPath, key)) : null;
+}