10 using System.Runtime.InteropServices;
20 [DllImport(
"ZLIB1.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Ansi)]
21 private static extern IntPtr gzopen(
string name,
string mode);
23 [DllImport(
"ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
24 private static extern int gzclose(IntPtr
gzFile);
26 [DllImport(
"ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
27 private static extern int gzwrite(IntPtr gzFile,
int data,
int length);
29 [DllImport(
"ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
30 private static extern int gzread(IntPtr gzFile,
int data,
int length);
32 [DllImport(
"ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
33 private static extern int gzgetc(IntPtr gzFile);
35 [DllImport(
"ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
36 private static extern int gzputc(IntPtr gzFile,
int c);
41 private IntPtr _gzFile;
42 private bool _isDisposed =
false;
43 private bool _isWriting;
56 _gzFile = gzopen(fileName, String.Format(
"wb{0}", (
int)level));
57 if (_gzFile == IntPtr.Zero)
69 _gzFile = gzopen(fileName,
"rb");
70 if (_gzFile == IntPtr.Zero)
76 #region Access properties 112 #region Destructor & IDispose stuff 131 private void cleanUp(
bool isDisposing)
141 #region Basic reading and writing 156 if (!
CanRead)
throw new NotSupportedException();
157 if (buffer == null)
throw new ArgumentNullException();
158 if (offset < 0 || count < 0)
throw new ArgumentOutOfRangeException();
159 if ((offset+count) > buffer.Length)
throw new ArgumentException();
160 if (_isDisposed)
throw new ObjectDisposedException(
"GZipStream");
162 GCHandle
h = GCHandle.Alloc(buffer, GCHandleType.Pinned);
166 result = gzread(_gzFile, h.AddrOfPinnedObject().ToInt32() +
offset,
count);
168 throw new IOException();
183 if (!
CanRead)
throw new NotSupportedException();
184 if (_isDisposed)
throw new ObjectDisposedException(
"GZipStream");
185 return gzgetc(_gzFile);
199 public override void Write(
byte[] buffer,
int offset,
int count)
201 if (!
CanWrite)
throw new NotSupportedException();
202 if (buffer == null)
throw new ArgumentNullException();
203 if (offset < 0 || count < 0)
throw new ArgumentOutOfRangeException();
204 if ((offset+count) > buffer.Length)
throw new ArgumentException();
205 if (_isDisposed)
throw new ObjectDisposedException(
"GZipStream");
207 GCHandle
h = GCHandle.Alloc(buffer, GCHandleType.Pinned);
212 throw new IOException();
228 if (!
CanWrite)
throw new NotSupportedException();
229 if (_isDisposed)
throw new ObjectDisposedException(
"GZipStream");
231 int result = gzputc(_gzFile, (
int)value);
233 throw new IOException();
237 #region Position & length stuff 245 throw new NotSupportedException();
257 throw new NotSupportedException();
279 throw new NotSupportedException();
283 throw new NotSupportedException();
292 public override long Length 296 throw new NotSupportedException();
GLenum GLuint GLenum GLsizei length
override long Position
Gets/sets the current position in the GZipStream.
GZipStream(string fileName, CompressLevel level)
Creates a new file as a writeable GZipStream
GLfloat GLfloat GLfloat GLfloat h
override void SetLength(long value)
Not supported.
override long Seek(long offset, SeekOrigin origin)
Not suppported.
GZipStream(string fileName)
Opens an existing file as a readable GZipStream
override int ReadByte()
Attempts to read a single byte from the stream.
override void WriteByte(byte value)
Writes a single byte to the stream
Implements a compressed Stream, in GZip (.gz) format.
override bool CanSeek
Returns false.
GLsizei GLsizei GLenum GLenum const GLvoid * data
override void Write(byte[] buffer, int offset, int count)
Writes a number of bytes to the stream
override long Length
Gets the size of the stream.
GLsizei const GLfloat * value
GLuint const GLchar * name
void Dispose()
Closes the external file handle
override int Read(byte[] buffer, int offset, int count)
Attempts to read a number of bytes from the stream.
override bool CanWrite
Returns true if this tsream is writeable, false otherwise
GLuint GLuint GLsizei count
CompressLevel
Defines constants for the available compression levels in zlib
override bool CanRead
Returns true of this stream can be read from, false otherwise
override void Flush()
Flushes the GZipStream.
The exception that is thrown when an error occurs on the zlib dll