1 /* -*- Mode: csharp; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
6 // Christopher James Lahey <clahey@ximian.com>
7 // Gonzalo Paniagua Javier <gonzalo@novell.com>
9 // Copyright (C) 2004-2010 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Runtime.InteropServices;
35 using System.Runtime.Remoting.Messaging;
37 namespace System.IO.Compression {
39 public class GZipStream : Stream
41 private DeflateStream deflateStream;
43 public GZipStream (Stream stream, CompressionMode mode) :
44 this (stream, mode, false) {
47 public GZipStream (Stream stream, CompressionMode mode, bool leaveOpen) {
48 this.deflateStream = new DeflateStream (stream, mode, leaveOpen, true);
52 public GZipStream (Stream stream, CompressionLevel compressionLevel)
53 : this (stream, compressionLevel, false)
57 public GZipStream (Stream stream, CompressionLevel compressionLevel, bool leaveOpen)
59 this.deflateStream = new DeflateStream (stream, compressionLevel, leaveOpen, true);
62 protected override void Dispose (bool disposing)
65 if (deflateStream != null) {
66 deflateStream.Dispose ();
70 base.Dispose (disposing);
73 public override int Read (byte[] array, int offset, int count)
75 if (deflateStream == null)
76 throw new ObjectDisposedException (GetType ().FullName);
78 return deflateStream.Read(array, offset, count);
82 public override void Write (byte[] array, int offset, int count)
84 if (deflateStream == null)
85 throw new ObjectDisposedException (GetType ().FullName);
87 deflateStream.Write (array, offset, count);
90 public override void Flush()
92 if (deflateStream == null)
93 throw new ObjectDisposedException (GetType ().FullName);
95 deflateStream.Flush();
98 public override long Seek (long offset, SeekOrigin origin)
100 throw new NotSupportedException();
103 public override void SetLength (long value)
105 throw new NotSupportedException();
108 public override IAsyncResult BeginRead (byte [] buffer, int offset, int count,
109 AsyncCallback cback, object state)
111 if (deflateStream == null)
112 throw new ObjectDisposedException (GetType ().FullName);
114 return deflateStream.BeginRead (buffer, offset, count, cback, state);
117 public override IAsyncResult BeginWrite (byte [] buffer, int offset, int count,
118 AsyncCallback cback, object state)
120 if (deflateStream == null)
121 throw new ObjectDisposedException (GetType ().FullName);
123 return deflateStream.BeginWrite (buffer, offset, count, cback, state);
126 public override int EndRead(IAsyncResult async_result) {
127 if (deflateStream == null)
128 throw new ObjectDisposedException (GetType ().FullName);
130 return deflateStream.EndRead (async_result);
133 public override void EndWrite (IAsyncResult async_result)
135 if (deflateStream == null)
136 throw new ObjectDisposedException (GetType ().FullName);
138 deflateStream.EndWrite (async_result);
141 public Stream BaseStream {
143 if (deflateStream == null)
146 return deflateStream.BaseStream;
150 public override bool CanRead {
152 if (deflateStream == null)
155 return deflateStream.CanRead;
159 public override bool CanSeek {
161 if (deflateStream == null)
164 return deflateStream.CanSeek;
168 public override bool CanWrite {
170 if (deflateStream == null)
173 return deflateStream.CanWrite;
177 public override long Length {
178 get { throw new NotSupportedException(); }
181 public override long Position {
182 get { throw new NotSupportedException(); }
183 set { throw new NotSupportedException(); }