/// <summary> /// Copy items from the current enumerable structure sequentially to a target indexable collection. /// </summary> /// <typeparam name="T">The type of the items capable of being enumerated.</typeparam> /// <param name="source">The current <see cref="IAsyncEnumerable{T}"/> implementation.</param> /// <param name="target">An indexable collection to copy enumerated items into.</param> /// <param name="token">A <see cref="CancellationToken"/> object.</param> /// <returns> /// A value corresponding to the number of items copied. /// </returns> public static Task <int> CopyToAsync <T>( this IAsyncEnumerable <T> source, IList <T> target, CancellationToken token = default(CancellationToken) ) { return(source.CopyToAsync(target, 0, target.Count, token)); }
public async Task <FileMetadata> UploadAsync(IAsyncEnumerable <RentedArray> stream, string fileName, CancellationToken token) { var tempFileName = Path.GetTempFileName(); long fileSize; using (var tempFile = new FileStream(tempFileName, FileMode.Create, FileAccess.ReadWrite)) { await stream.CopyToAsync(tempFile, token); fileSize = tempFile.Length; } File.Delete(tempFileName); return(new FileMetadata(fileName, fileSize)); }
public static Task CopyToAsync( this IAsyncEnumerable <StreamPartition> partitions, FileInfo destination, bool async, CancellationToken cancellationToken) => partitions.CopyToAsync(destination.OpenWrite(), async, cancellationToken);