Example #1
0
        public static IPromise <string> ReadTextAsync(LocalFile file)
        {
            var promise = new Promise <string>();

            Task.Run(async() => {
                try {
                    using var reader = new StreamReader(file.Uri);
                    var text         = await reader.ReadToEndAsync();
                    promise.Resolve(text);
                }
                catch (Exception e) {
                    promise.Reject(e);
                }
            });

            return(promise);
        }
Example #2
0
        public static IPromise WriteTextAsync(LocalFile file, string text)
        {
            var promise = new Promise();

            Task.Run(async() => {
                try {
                    using var writer = new StreamWriter(file.Uri);
                    await writer.WriteAsync(text);
                    promise.Resolve();
                }
                catch (Exception e) {
                    promise.Reject(e);
                }
            });

            return(promise);
        }
Example #3
0
 public LocalFile GetFile(string uri)
 => LocalFile.At(this.GetUriWithin_(uri));
Example #4
0
 public static byte[] ReadBytes(LocalFile file) =>
 File.ReadAllBytes(file.Uri);
Example #5
0
 public static string ReadText(LocalFile file)
 {
     using var reader = new StreamReader(file.Uri);
     return(reader.ReadToEnd());
 }