Example #1
0
 public static async Task <byte[]> ReadAllBytesAsync(this IStorageRecord record, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var source = await record.CreateReadableStreamAsync(cancellationToken))
     {
         return(await source.ToByteArrayAsync(cancellationToken));
     }
 }
Example #2
0
        public static async Task CopyToAsync(
            this IStorageRecord record,
            Stream destination,
            int?bufferSize     = null,
            IProgress progress = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (record.GetStorageProvider().Features.TryGetFeature(out IRecordCopyFeature implementation))
            {
                await implementation.CopyToAsync(record, destination, bufferSize, progress, cancellationToken);
            }
            else
            {
                using (var buffer = await record.CreateReadableStreamAsync(cancellationToken))
                {
                    await buffer.CopyToAsync(destination, bufferSize ?? 8192, progress, cancellationToken);

                    await destination.FlushAsync();
                }
            }
        }
Example #3
0
 public static Stream CreateReadableStream(this IStorageRecord storageRecord) => storageRecord.CreateReadableStreamAsync().GetAwaiter().GetResult();