public async Task <TryResult <string> > TryReadTextFileAsync(string path) { string content = ""; bool operationSucceeded = await TryReadFileCommonAsync(path, async stream => { using (var reader = new StreamReader(stream)) { content = await reader.ReadToEndAsync().ConfigureAwait(false); return(true); }; }).ConfigureAwait(false); return(TryResult.Create(operationSucceeded, content)); }
public async Task <TryResult <byte[]> > TryReadBinaryFileAsync(string path) { byte[] content = null; bool operationSucceeded = await TryReadFileCommonAsync(path, async stream => { using (var ms = new MemoryStream()) { await stream.CopyToAsync(ms).ConfigureAwait(false); content = ms.ToArray(); return(true); } }).ConfigureAwait(false); return(TryResult.Create(operationSucceeded, content)); }