Fix build_init vcxproj to correctly detect changes in config.h.
[mono.git] / mcs / class / System / System.IO.Compression / GZipStream.cs
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 <clahey@ximian.com>
7 //      Gonzalo Paniagua Javier <gonzalo@novell.com>
8 //
9 // Copyright (C) 2004-2010 Novell, Inc (http://www.novell.com)
10 //
11 //
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:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
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.
30 //
31
32 using System;
33 using System.IO;
34 using System.Runtime.InteropServices;
35 using System.Runtime.Remoting.Messaging;
36
37 namespace System.IO.Compression {
38
39         public class GZipStream : Stream
40         {
41                 private DeflateStream deflateStream;
42
43                 public GZipStream (Stream stream, CompressionMode mode) :
44                         this (stream, mode, false) {
45                 }
46
47                 public GZipStream (Stream stream, CompressionMode mode, bool leaveOpen) {
48                         this.deflateStream = new DeflateStream (stream, mode, leaveOpen, true);
49                 }
50                 
51                 
52                 public GZipStream (Stream stream, CompressionLevel compressionLevel)
53                         : this (stream, compressionLevel, false)
54                 {
55                 }
56                 
57                 public GZipStream (Stream stream, CompressionLevel compressionLevel, bool leaveOpen)
58                 {
59                         this.deflateStream = new DeflateStream (stream, compressionLevel, leaveOpen, true);
60                 }
61
62                 protected override void Dispose (bool disposing)
63                 {
64                         if (disposing) {
65                                 if (deflateStream != null) {
66                                         deflateStream.Dispose ();
67                                         deflateStream = null;
68                                 }
69                         }
70                         base.Dispose (disposing);
71                 }
72
73                 public override int Read (byte[] array, int offset, int count)
74                 {
75                         if (deflateStream == null)
76                                 throw new ObjectDisposedException (GetType ().FullName);
77
78                         return deflateStream.Read(array, offset, count);
79                 }
80
81
82                 public override void Write (byte[] array, int offset, int count)
83                 {
84                         if (deflateStream == null)
85                                 throw new ObjectDisposedException (GetType ().FullName);
86
87                         deflateStream.Write (array, offset, count);
88                 }
89
90                 public override void Flush()
91                 {
92                         if (deflateStream == null)
93                                 throw new ObjectDisposedException (GetType ().FullName);
94
95                         deflateStream.Flush();
96                 }
97
98                 public override long Seek (long offset, SeekOrigin origin)
99                 {
100                         throw new NotSupportedException();
101                 }
102
103                 public override void SetLength (long value)
104                 {
105                         throw new NotSupportedException();
106                 }
107
108                 public override IAsyncResult BeginRead (byte [] buffer, int offset, int count,
109                                                         AsyncCallback cback, object state)
110                 {
111                         if (deflateStream == null)
112                                 throw new ObjectDisposedException (GetType ().FullName);
113
114                         return deflateStream.BeginRead (buffer, offset, count, cback, state);
115                 }
116
117                 public override IAsyncResult BeginWrite (byte [] buffer, int offset, int count,
118                                                         AsyncCallback cback, object state)
119                 {
120                         if (deflateStream == null)
121                                 throw new ObjectDisposedException (GetType ().FullName);
122
123                         return deflateStream.BeginWrite (buffer, offset, count, cback, state);
124                 }
125
126                 public override int EndRead(IAsyncResult async_result) {
127                         if (deflateStream == null)
128                                 throw new ObjectDisposedException (GetType ().FullName);
129
130                         return deflateStream.EndRead (async_result);
131                 }
132
133                 public override void EndWrite (IAsyncResult async_result)
134                 {
135                         if (deflateStream == null)
136                                 throw new ObjectDisposedException (GetType ().FullName);
137
138                         deflateStream.EndWrite (async_result);
139                 }
140
141                 public Stream BaseStream {
142                         get {
143                                 if (deflateStream == null)
144                                         return null;
145
146                                 return deflateStream.BaseStream;
147                         }
148                 }
149
150                 public override bool CanRead {
151                         get {
152                                 if (deflateStream == null)
153                                         return false;
154
155                                 return deflateStream.CanRead;
156                         }
157                 }
158
159                 public override bool CanSeek {
160                         get {
161                                 if (deflateStream == null)
162                                         return false;
163
164                                 return deflateStream.CanSeek;
165                         }
166                 }
167
168                 public override bool CanWrite {
169                         get {
170                                 if (deflateStream == null)
171                                         return false;
172
173                                 return deflateStream.CanWrite;
174                         }
175                 }
176
177                 public override long Length {
178                         get { throw new NotSupportedException(); }
179                 }
180
181                 public override long Position {
182                         get { throw new NotSupportedException(); }
183                         set { throw new NotSupportedException(); }
184                 }
185         }
186 }
187
188