GzipStream.cs 3.6 KB

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