Exemplo n.º 1
0
 /// <summary>
 /// Read contents of a file as a string. See: https://github.com/FrendsPlatform/Frends.File#Read
 /// </summary>
 /// <returns>Object {string Content, string Path, double SizeInMegaBytes, DateTime CreationTime, DateTime LastWriteTime }  </returns>
 public static async Task <ReadResult> Read([PropertyTab] ReadInput input, [PropertyTab] ReadOption options)
 {
     return(await ExecuteActionAsync(
                () => ExecuteRead(input, options),
                options.UseGivenUserCredentialsForRemoteConnections,
                options.UserName,
                options.Password)
            .ConfigureAwait(false));
 }
Exemplo n.º 2
0
        private static async Task <ReadResult> ExecuteRead(ReadInput input, ReadOption options)
        {
            var encoding = GetEncoding(options.FileEncoding, options.EnableBom, options.EncodingInString);

            using (var fileStream = new FileStream(input.Path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, useAsync: true))
                using (var reader = new StreamReader(fileStream, encoding, detectEncodingFromByteOrderMarks: true))
                {
                    var content = await reader.ReadToEndAsync().ConfigureAwait(false);

                    return(new ReadResult(new FileInfo(input.Path), content));
                }
        }