GzipStream.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. deflateStream.Dispose ();
  49. base.Dispose (disposing);
  50. }
  51. public override int Read (byte[] dest, int dest_offset, int count)
  52. {
  53. return deflateStream.Read(dest, dest_offset, count);
  54. }
  55. public override void Write (byte[] src, int src_offset, int count)
  56. {
  57. deflateStream.Write (src, src_offset, count);
  58. }
  59. public override void Flush() {
  60. deflateStream.Flush();
  61. }
  62. public override long Seek (long offset, SeekOrigin origin) {
  63. return deflateStream.Seek (offset, origin);
  64. }
  65. public override void SetLength (long value) {
  66. deflateStream.SetLength (value);
  67. }
  68. public override IAsyncResult BeginRead (byte [] buffer, int offset, int count,
  69. AsyncCallback cback, object state)
  70. {
  71. return deflateStream.BeginRead (buffer, offset, count, cback, state);
  72. }
  73. public override IAsyncResult BeginWrite (byte [] buffer, int offset, int count,
  74. AsyncCallback cback, object state)
  75. {
  76. return deflateStream.BeginWrite (buffer, offset, count, cback, state);
  77. }
  78. public override int EndRead(IAsyncResult async_result) {
  79. return deflateStream.EndRead (async_result);
  80. }
  81. public override void EndWrite (IAsyncResult async_result)
  82. {
  83. deflateStream.EndWrite (async_result);
  84. }
  85. public Stream BaseStream {
  86. get {
  87. return deflateStream.BaseStream;
  88. }
  89. }
  90. public override bool CanRead {
  91. get {
  92. return deflateStream.CanRead;
  93. }
  94. }
  95. public override bool CanSeek {
  96. get {
  97. return deflateStream.CanSeek;
  98. }
  99. }
  100. public override bool CanWrite {
  101. get {
  102. return deflateStream.CanWrite;
  103. }
  104. }
  105. public override long Length {
  106. get {
  107. return deflateStream.Length;
  108. }
  109. }
  110. public override long Position {
  111. get {
  112. return deflateStream.Position;
  113. }
  114. set {
  115. deflateStream.Position = value;
  116. }
  117. }
  118. }
  119. }
  120. #endif