GzipStream.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* -*- Mode: csharp; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
  2. //
  3. // GZipStream.cs
  4. //
  5. // Authors:
  6. // Christopher James Lahey <[email protected]>
  7. //
  8. // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. #if NET_2_0
  31. using System;
  32. using System.IO;
  33. using System.Runtime.InteropServices;
  34. using System.Runtime.Remoting.Messaging;
  35. namespace System.IO.Compression {
  36. public class GZipStream : Stream
  37. {
  38. private DeflateStream deflateStream;
  39. public GZipStream (Stream compressedStream, CompressionMode mode) :
  40. this (compressedStream, mode, false) {
  41. }
  42. public GZipStream (Stream compressedStream, CompressionMode mode, bool leaveOpen) {
  43. this.deflateStream = new DeflateStream (compressedStream, mode, leaveOpen, true);
  44. }
  45. protected override void Dispose (bool disposing)
  46. {
  47. if (disposing) {
  48. if (deflateStream != null) {
  49. deflateStream.Dispose ();
  50. deflateStream = null;
  51. }
  52. }
  53. base.Dispose (disposing);
  54. }
  55. public override int Read (byte[] dest, int dest_offset, int count)
  56. {
  57. return deflateStream.Read(dest, dest_offset, count);
  58. }
  59. public override void Write (byte[] src, int src_offset, int count)
  60. {
  61. deflateStream.Write (src, src_offset, count);
  62. }
  63. public override void Flush() {
  64. deflateStream.Flush();
  65. }
  66. public override long Seek (long offset, SeekOrigin origin) {
  67. return deflateStream.Seek (offset, origin);
  68. }
  69. public override void SetLength (long value) {
  70. deflateStream.SetLength (value);
  71. }
  72. public override IAsyncResult BeginRead (byte [] buffer, int offset, int count,
  73. AsyncCallback cback, object state)
  74. {
  75. return deflateStream.BeginRead (buffer, offset, count, cback, state);
  76. }
  77. public override IAsyncResult BeginWrite (byte [] buffer, int offset, int count,
  78. AsyncCallback cback, object state)
  79. {
  80. return deflateStream.BeginWrite (buffer, offset, count, cback, state);
  81. }
  82. public override int EndRead(IAsyncResult async_result) {
  83. return deflateStream.EndRead (async_result);
  84. }
  85. public override void EndWrite (IAsyncResult async_result)
  86. {
  87. deflateStream.EndWrite (async_result);
  88. }
  89. public Stream BaseStream {
  90. get {
  91. return deflateStream.BaseStream;
  92. }
  93. }
  94. public override bool CanRead {
  95. get {
  96. return deflateStream.CanRead;
  97. }
  98. }
  99. public override bool CanSeek {
  100. get {
  101. return deflateStream.CanSeek;
  102. }
  103. }
  104. public override bool CanWrite {
  105. get {
  106. return deflateStream.CanWrite;
  107. }
  108. }
  109. public override long Length {
  110. get {
  111. return deflateStream.Length;
  112. }
  113. }
  114. public override long Position {
  115. get {
  116. return deflateStream.Position;
  117. }
  118. set {
  119. deflateStream.Position = value;
  120. }
  121. }
  122. }
  123. }
  124. #endif