/// <summary> /// Alternative stream copy method to CopyTo. Stops writing when no more data is available from input. /// </summary> public static long TransferTo(this Stream source, Stream destination, Archive.IProgressProvider progress = null) { byte[] array = getTransferByteArray(); int count; long total = 0; while ((count = source.Read(array, 0, array.Length)) > 0) { destination.Write(array, 0, count); total += count; if (progress != null) { progress.SetProgress((ulong)total, 0); } } return(total); }
/// <summary> /// Alternative stream copy method to CopyTo. Stops writing when count is reached. /// </summary> public static long TransferTo(this Stream source, Stream destination, long count, Archive.IProgressProvider progress = null) { if (count == 0) { throw new ArgumentOutOfRangeException(); } byte[] array = getTransferByteArray(); long total = 0; while (count > 0) { int next = array.Length; if (next > count) { next = (int)count; } int r = source.Read(array, 0, next); if (r == 0) { break; } total += r; count -= r; destination.Write(array, 0, r); if (progress != null) { progress.SetProgress((ulong)total, 0); } } return(total); }