From 83029c478f411bcadd3be53ac4dc53d88b3c8462 Mon Sep 17 00:00:00 2001 From: "Emma@Rory&" Date: Mon, 14 Aug 2023 19:46:33 +0200 Subject: Code cleanup --- MatrixRoomUtils.Desktop/FileStorageProvider.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'MatrixRoomUtils.Desktop/FileStorageProvider.cs') diff --git a/MatrixRoomUtils.Desktop/FileStorageProvider.cs b/MatrixRoomUtils.Desktop/FileStorageProvider.cs index 36a3c7e..b3850b0 100644 --- a/MatrixRoomUtils.Desktop/FileStorageProvider.cs +++ b/MatrixRoomUtils.Desktop/FileStorageProvider.cs @@ -23,20 +23,24 @@ public class FileStorageProvider : IStorageProvider { } } - public async Task SaveObjectAsync(string key, T value) => await File.WriteAllTextAsync(Path.Join(TargetPath, key), ObjectExtensions.ToJson(value)); + public async Task SaveObjectAsync(string key, T value) => await File.WriteAllTextAsync(Path.Join(TargetPath, key), value?.ToJson()); public async Task LoadObjectAsync(string key) => JsonSerializer.Deserialize(await File.ReadAllTextAsync(Path.Join(TargetPath, key))); - public async Task ObjectExistsAsync(string key) => File.Exists(Path.Join(TargetPath, key)); + public Task ObjectExistsAsync(string key) => Task.FromResult(File.Exists(Path.Join(TargetPath, key))); - public async Task> GetAllKeysAsync() => Directory.GetFiles(TargetPath).Select(Path.GetFileName).ToList(); + public Task> GetAllKeysAsync() => Task.FromResult(Directory.GetFiles(TargetPath).Select(Path.GetFileName).ToList()); + + public Task DeleteObjectAsync(string key) { + File.Delete(Path.Join(TargetPath, key)); + return Task.CompletedTask; + } - public async Task DeleteObjectAsync(string key) => File.Delete(Path.Join(TargetPath, key)); 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; + public Task LoadStreamAsync(string key) => Task.FromResult(File.Exists(Path.Join(TargetPath, key)) ? File.OpenRead(Path.Join(TargetPath, key)) : null); } -- cgit 1.5.1