Exemplo n.º 1
0
 /// <summary>
 /// Read contents of a file as a byte array. See: hhttps://github.com/FrendsPlatform/Frends.File#ReadBytes
 /// </summary>
 /// <returns>Object {byte[] ContentBytes, string Path, double SizeInMegaBytes, DateTime CreationTime, DateTime LastWriteTime }  </returns>
 public static async Task <ReadBytesResult> ReadBytes([PropertyTab] ReadInput input, [PropertyTab] ReadBytesOption options)
 {
     return(await ExecuteActionAsync(
                () => ExecuteReadBytes(input, options),
                options.UseGivenUserCredentialsForRemoteConnections,
                options.UserName,
                options.Password)
            .ConfigureAwait(false));
 }
Exemplo n.º 2
0
        private static async Task <ReadBytesResult> ExecuteReadBytes(ReadInput input, ReadBytesOption options)
        {
            using (var file = new FileStream(input.Path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, useAsync: true))
            {
                var buffer = new byte[file.Length];
                await file.ReadAsync(buffer, 0, (int)file.Length).ConfigureAwait(false);

                return(new ReadBytesResult(new FileInfo(input.Path), buffer));
            }
        }