Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

PackagePartStream.cs 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System.IO;
  2. using System.Threading;
  3. namespace Novacode
  4. {
  5. /// <summary>
  6. /// See <a href="https://support.microsoft.com/en-gb/kb/951731" /> for explanation
  7. /// </summary>
  8. public class PackagePartStream : Stream
  9. {
  10. private static readonly Mutex Mutex = new Mutex(false);
  11. private readonly Stream stream;
  12. public PackagePartStream(Stream stream)
  13. {
  14. this.stream = stream;
  15. }
  16. public override bool CanRead
  17. {
  18. get { return this.stream.CanRead; }
  19. }
  20. public override bool CanSeek
  21. {
  22. get { return this.stream.CanSeek; }
  23. }
  24. public override bool CanWrite
  25. {
  26. get { return this.stream.CanWrite; }
  27. }
  28. public override long Length
  29. {
  30. get { return this.stream.Length; }
  31. }
  32. public override long Position
  33. {
  34. get { return this.stream.Position; }
  35. set { this.stream.Position = value; }
  36. }
  37. public override long Seek(long offset, SeekOrigin origin)
  38. {
  39. return this.stream.Seek(offset, origin);
  40. }
  41. public override void SetLength(long value)
  42. {
  43. this.stream.SetLength(value);
  44. }
  45. public override int Read(byte[] buffer, int offset, int count)
  46. {
  47. return this.stream.Read(buffer, offset, count);
  48. }
  49. public override void Write(byte[] buffer, int offset, int count)
  50. {
  51. Mutex.WaitOne(Timeout.Infinite, false);
  52. this.stream.Write(buffer, offset, count);
  53. Mutex.ReleaseMutex();
  54. }
  55. public override void Flush()
  56. {
  57. Mutex.WaitOne(Timeout.Infinite, false);
  58. this.stream.Flush();
  59. Mutex.ReleaseMutex();
  60. }
  61. public override void Close()
  62. {
  63. this.stream.Close();
  64. }
  65. protected override void Dispose(bool disposing)
  66. {
  67. this.stream.Dispose();
  68. }
  69. }
  70. }