diff options
Diffstat (limited to 'MatrixRoomUtils.Desktop/FileStorageProvider.cs')
-rw-r--r-- | MatrixRoomUtils.Desktop/FileStorageProvider.cs | 14 |
1 files changed, 9 insertions, 5 deletions
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<T>(string key, T value) => await File.WriteAllTextAsync(Path.Join(TargetPath, key), ObjectExtensions.ToJson(value)); + public async Task SaveObjectAsync<T>(string key, T value) => await File.WriteAllTextAsync(Path.Join(TargetPath, key), value?.ToJson()); public async Task<T?> LoadObjectAsync<T>(string key) => JsonSerializer.Deserialize<T>(await File.ReadAllTextAsync(Path.Join(TargetPath, key))); - public async Task<bool> ObjectExistsAsync(string key) => File.Exists(Path.Join(TargetPath, key)); + public Task<bool> ObjectExistsAsync(string key) => Task.FromResult(File.Exists(Path.Join(TargetPath, key))); - public async Task<List<string>> GetAllKeysAsync() => Directory.GetFiles(TargetPath).Select(Path.GetFileName).ToList(); + public Task<List<string>> 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<Stream?> LoadStreamAsync(string key) => File.Exists(Path.Join(TargetPath, key)) ? File.OpenRead(Path.Join(TargetPath, key)) : null; + public Task<Stream?> LoadStreamAsync(string key) => Task.FromResult<Stream?>(File.Exists(Path.Join(TargetPath, key)) ? File.OpenRead(Path.Join(TargetPath, key)) : null); } |