StreamHelper.cs 747 B

123456789101112131415161718192021222324252627
  1. using System.IO;
  2. using System.Threading;
  3. using System;
  4. namespace MediaBrowser.Controller.IO
  5. {
  6. public static class StreamHelper
  7. {
  8. public static void CopyTo(Stream source, Stream destination, int bufferSize, Action onStarted, CancellationToken cancellationToken)
  9. {
  10. byte[] buffer = new byte[bufferSize];
  11. int read;
  12. while ((read = source.Read(buffer, 0, buffer.Length)) != 0)
  13. {
  14. cancellationToken.ThrowIfCancellationRequested();
  15. destination.Write(buffer, 0, read);
  16. if (onStarted != null)
  17. {
  18. onStarted();
  19. onStarted = null;
  20. }
  21. }
  22. }
  23. }
  24. }