OffsetStream.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // OffsetStream.cs
  2. // ------------------------------------------------------------------
  3. //
  4. // Copyright (c) 2009 Dino Chiesa
  5. // All rights reserved.
  6. //
  7. // This code module is part of DotNetZip, a zipfile class library.
  8. //
  9. // ------------------------------------------------------------------
  10. //
  11. // This code is licensed under the Microsoft Public License.
  12. // See the file License.txt for the license details.
  13. // More info on: http://dotnetzip.codeplex.com
  14. //
  15. // ------------------------------------------------------------------
  16. //
  17. // last saved (in emacs):
  18. // Time-stamp: <2009-August-27 12:50:35>
  19. //
  20. // ------------------------------------------------------------------
  21. //
  22. // This module defines logic for handling reading of zip archives embedded
  23. // into larger streams. The initial position of the stream serves as
  24. // the base offset for all future Seek() operations.
  25. //
  26. // ------------------------------------------------------------------
  27. using System;
  28. using System.IO;
  29. namespace Ionic.Zip
  30. {
  31. internal class OffsetStream : System.IO.Stream, System.IDisposable
  32. {
  33. private Int64 _originalPosition;
  34. private Stream _innerStream;
  35. public OffsetStream(Stream s)
  36. : base()
  37. {
  38. _originalPosition = s.Position;
  39. _innerStream = s;
  40. }
  41. public override int Read(byte[] buffer, int offset, int count)
  42. {
  43. return _innerStream.Read(buffer, offset, count);
  44. }
  45. public override void Write(byte[] buffer, int offset, int count)
  46. {
  47. throw new NotImplementedException();
  48. }
  49. public override bool CanRead
  50. {
  51. get { return _innerStream.CanRead; }
  52. }
  53. public override bool CanSeek
  54. {
  55. get { return _innerStream.CanSeek; }
  56. }
  57. public override bool CanWrite
  58. {
  59. get { return false; }
  60. }
  61. public override void Flush()
  62. {
  63. _innerStream.Flush();
  64. }
  65. public override long Length
  66. {
  67. get
  68. {
  69. return _innerStream.Length;
  70. }
  71. }
  72. public override long Position
  73. {
  74. get { return _innerStream.Position - _originalPosition; }
  75. set { _innerStream.Position = _originalPosition + value; }
  76. }
  77. public override long Seek(long offset, System.IO.SeekOrigin origin)
  78. {
  79. return _innerStream.Seek(_originalPosition + offset, origin) - _originalPosition;
  80. }
  81. public override void SetLength(long value)
  82. {
  83. throw new NotImplementedException();
  84. }
  85. void IDisposable.Dispose()
  86. {
  87. Close();
  88. }
  89. public override void Close()
  90. {
  91. base.Close();
  92. }
  93. }
  94. }