CountingWritableSubStream.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.IO;
  3. namespace SharpCompress.IO
  4. {
  5. internal class CountingWritableSubStream : Stream
  6. {
  7. private readonly Stream writableStream;
  8. internal CountingWritableSubStream(Stream stream)
  9. {
  10. writableStream = stream;
  11. }
  12. public ulong Count { get; private set; }
  13. public override bool CanRead => false;
  14. public override bool CanSeek => false;
  15. public override bool CanWrite => true;
  16. public override void Flush()
  17. {
  18. writableStream.Flush();
  19. }
  20. public override long Length => throw new NotSupportedException();
  21. public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); }
  22. public override int Read(byte[] buffer, int offset, int count)
  23. {
  24. throw new NotSupportedException();
  25. }
  26. public override long Seek(long offset, SeekOrigin origin)
  27. {
  28. throw new NotSupportedException();
  29. }
  30. public override void SetLength(long value)
  31. {
  32. throw new NotSupportedException();
  33. }
  34. public override void Write(byte[] buffer, int offset, int count)
  35. {
  36. writableStream.Write(buffer, offset, count);
  37. Count += (uint)count;
  38. }
  39. public override void WriteByte(byte value)
  40. {
  41. writableStream.WriteByte(value);
  42. ++Count;
  43. }
  44. }
  45. }