Rizin
unix-like reverse engineering framework and cli tools
DotZLib.GZipStream Class Reference

Implements a compressed Stream, in GZip (.gz) format. More...

Inheritance diagram for DotZLib.GZipStream:
Stream

Public Member Functions

 GZipStream (string fileName, CompressLevel level)
 Creates a new file as a writeable GZipStream More...
 
 GZipStream (string fileName)
 Opens an existing file as a readable GZipStream More...
 
void Dispose ()
 Closes the external file handle More...
 
override int Read (byte[] buffer, int offset, int count)
 Attempts to read a number of bytes from the stream. More...
 
override int ReadByte ()
 Attempts to read a single byte from the stream. More...
 
override void Write (byte[] buffer, int offset, int count)
 Writes a number of bytes to the stream More...
 
override void WriteByte (byte value)
 Writes a single byte to the stream More...
 
override void SetLength (long value)
 Not supported. More...
 
override long Seek (long offset, SeekOrigin origin)
 Not suppported. More...
 
override void Flush ()
 Flushes the GZipStream. More...
 

Properties

override bool CanRead [get]
 Returns true of this stream can be read from, false otherwise More...
 
override bool CanSeek [get]
 Returns false. More...
 
override bool CanWrite [get]
 Returns true if this tsream is writeable, false otherwise More...
 
override long Position [get, set]
 Gets/sets the current position in the GZipStream. Not suppported. More...
 
override long Length [get]
 Gets the size of the stream. Not suppported. More...
 

Private Member Functions

static IntPtr gzopen (string name, string mode)
 
static int gzclose (IntPtr gzFile)
 
static int gzwrite (IntPtr gzFile, int data, int length)
 
static int gzread (IntPtr gzFile, int data, int length)
 
static int gzgetc (IntPtr gzFile)
 
static int gzputc (IntPtr gzFile, int c)
 
 ~GZipStream ()
 Destroys this instance More...
 
void cleanUp (bool isDisposing)
 

Private Attributes

IntPtr _gzFile
 
bool _isDisposed = false
 
bool _isWriting
 

Additional Inherited Members

- Public Attributes inherited from Stream
const char * input
 
const char * start
 
const char * end
 
int32_t next
 
uint8_t next_size
 

Detailed Description

Implements a compressed Stream, in GZip (.gz) format.

Definition at line 17 of file GZipStream.cs.

Constructor & Destructor Documentation

◆ GZipStream() [1/2]

DotZLib.GZipStream.GZipStream ( string  fileName,
CompressLevel  level 
)
inline

Creates a new file as a writeable GZipStream

Parameters
fileNameThe name of the compressed file to create
levelThe compression level to use when adding data
Exceptions
ZLibExceptionIf an error occurred in the internal zlib function

Definition at line 53 of file GZipStream.cs.

54  {
55  _isWriting = true;
56  _gzFile = gzopen(fileName, String.Format("wb{0}", (int)level));
57  if (_gzFile == IntPtr.Zero)
58  throw new ZLibException(-1, "Could not open " + fileName);
59  }
static IntPtr gzopen(string name, string mode)
static int level
Definition: vmenus.c:2424

References DotZLib.GZipStream._gzFile, DotZLib.GZipStream._isWriting, test-lz4-speed.fileName, DotZLib.GZipStream.gzopen(), and level.

◆ GZipStream() [2/2]

DotZLib.GZipStream.GZipStream ( string  fileName)
inline

Opens an existing file as a readable GZipStream

Parameters
fileNameThe name of the file to open
Exceptions
ZLibExceptionIf an error occurred in the internal zlib function

Definition at line 66 of file GZipStream.cs.

67  {
68  _isWriting = false;
69  _gzFile = gzopen(fileName, "rb");
70  if (_gzFile == IntPtr.Zero)
71  throw new ZLibException(-1, "Could not open " + fileName);
72 
73  }

References DotZLib.GZipStream._gzFile, DotZLib.GZipStream._isWriting, test-lz4-speed.fileName, and DotZLib.GZipStream.gzopen().

◆ ~GZipStream()

DotZLib.GZipStream.~GZipStream ( )
inlineprivate

Destroys this instance

Definition at line 117 of file GZipStream.cs.

118  {
119  cleanUp(false);
120  }
void cleanUp(bool isDisposing)
Definition: GZipStream.cs:131

References DotZLib.GZipStream.cleanUp().

Member Function Documentation

◆ cleanUp()

void DotZLib.GZipStream.cleanUp ( bool  isDisposing)
inlineprivate

Definition at line 131 of file GZipStream.cs.

132  {
133  if (!_isDisposed)
134  {
135  gzclose(_gzFile);
136  _isDisposed = true;
137  }
138  }
static int gzclose(IntPtr gzFile)

References DotZLib.GZipStream._gzFile, DotZLib.GZipStream._isDisposed, and DotZLib.GZipStream.gzclose().

Referenced by DotZLib.GZipStream.Dispose(), and DotZLib.GZipStream.~GZipStream().

◆ Dispose()

void DotZLib.GZipStream.Dispose ( )
inline

Closes the external file handle

Definition at line 125 of file GZipStream.cs.

126  {
127  cleanUp(true);
128  }

References DotZLib.GZipStream.cleanUp().

◆ Flush()

override void DotZLib.GZipStream.Flush ( )
inline

Flushes the GZipStream.

In this implementation, this method does nothing. This is because excessive flushing may degrade the achievable compression rates.

Definition at line 265 of file GZipStream.cs.

266  {
267  // left empty on purpose
268  }

◆ gzclose()

static int DotZLib.GZipStream.gzclose ( IntPtr  gzFile)
private

◆ gzgetc()

static int DotZLib.GZipStream.gzgetc ( IntPtr  gzFile)
private

◆ gzopen()

static IntPtr DotZLib.GZipStream.gzopen ( string  name,
string  mode 
)
private

◆ gzputc()

static int DotZLib.GZipStream.gzputc ( IntPtr  gzFile,
int  c 
)
private

◆ gzread()

static int DotZLib.GZipStream.gzread ( IntPtr  gzFile,
int  data,
int  length 
)
private

Referenced by DotZLib.GZipStream.Read().

◆ gzwrite()

static int DotZLib.GZipStream.gzwrite ( IntPtr  gzFile,
int  data,
int  length 
)
private

◆ Read()

override int DotZLib.GZipStream.Read ( byte[]  buffer,
int  offset,
int  count 
)
inline

Attempts to read a number of bytes from the stream.

Parameters
bufferThe destination data buffer
offsetThe index of the first destination byte in buffer
countThe number of bytes requested
Returns
The number of bytes read
Exceptions
ArgumentNullExceptionIf buffer is null
ArgumentOutOfRangeExceptionIf count or offset are negative
ArgumentExceptionIf offset + count is > buffer.Length
NotSupportedExceptionIf this stream is not readable.
ObjectDisposedExceptionIf this stream has been disposed.

Definition at line 154 of file GZipStream.cs.

155  {
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");
161 
162  GCHandle h = GCHandle.Alloc(buffer, GCHandleType.Pinned);
163  int result;
164  try
165  {
166  result = gzread(_gzFile, h.AddrOfPinnedObject().ToInt32() + offset, count);
167  if (result < 0)
168  throw new IOException();
169  }
170  finally
171  {
172  h.Free();
173  }
174  return result;
175  }
static int gzread(IntPtr gzFile, int data, int length)
override bool CanRead
Returns true of this stream can be read from, false otherwise
Definition: GZipStream.cs:81
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
voidpf uLong offset
Definition: ioapi.h:144
#define h(i)
Definition: sha256.c:48
Definition: buffer.h:15

References DotZLib.GZipStream._gzFile, DotZLib.GZipStream._isDisposed, DotZLib.GZipStream.CanRead, count, DotZLib.GZipStream.gzread(), and h.

◆ ReadByte()

override int DotZLib.GZipStream.ReadByte ( )
inline

Attempts to read a single byte from the stream.

Returns
The byte that was read, or -1 in case of error or End-Of-File

Definition at line 181 of file GZipStream.cs.

182  {
183  if (!CanRead) throw new NotSupportedException();
184  if (_isDisposed) throw new ObjectDisposedException("GZipStream");
185  return gzgetc(_gzFile);
186  }
static int gzgetc(IntPtr gzFile)

References DotZLib.GZipStream._gzFile, DotZLib.GZipStream._isDisposed, DotZLib.GZipStream.CanRead, and DotZLib.GZipStream.gzgetc().

◆ Seek()

override long DotZLib.GZipStream.Seek ( long  offset,
SeekOrigin  origin 
)
inline

Not suppported.

Parameters
offset
origin
Returns
Exceptions
NotSupportedExceptionAlways thrown

Definition at line 255 of file GZipStream.cs.

256  {
257  throw new NotSupportedException();
258  }

◆ SetLength()

override void DotZLib.GZipStream.SetLength ( long  value)
inline

Not supported.

Parameters
value
Exceptions
NotSupportedExceptionAlways thrown

Definition at line 243 of file GZipStream.cs.

244  {
245  throw new NotSupportedException();
246  }

◆ Write()

override void DotZLib.GZipStream.Write ( byte[]  buffer,
int  offset,
int  count 
)
inline

Writes a number of bytes to the stream

Parameters
buffer
offset
count
Exceptions
ArgumentNullExceptionIf buffer is null
ArgumentOutOfRangeExceptionIf count or offset are negative
ArgumentExceptionIf offset + count is > buffer.Length
NotSupportedExceptionIf this stream is not writeable.
ObjectDisposedExceptionIf this stream has been disposed.

Definition at line 199 of file GZipStream.cs.

200  {
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");
206 
207  GCHandle h = GCHandle.Alloc(buffer, GCHandleType.Pinned);
208  try
209  {
210  int result = gzwrite(_gzFile, h.AddrOfPinnedObject().ToInt32() + offset, count);
211  if (result < 0)
212  throw new IOException();
213  }
214  finally
215  {
216  h.Free();
217  }
218  }
static int gzwrite(IntPtr gzFile, int data, int length)
override bool CanWrite
Returns true if this tsream is writeable, false otherwise
Definition: GZipStream.cs:104

References DotZLib.GZipStream._gzFile, DotZLib.GZipStream._isDisposed, DotZLib.GZipStream.CanWrite, count, DotZLib.GZipStream.gzwrite(), and h.

◆ WriteByte()

override void DotZLib.GZipStream.WriteByte ( byte  value)
inline

Writes a single byte to the stream

Parameters
valueThe byte to add to the stream.
Exceptions
NotSupportedExceptionIf this stream is not writeable.
ObjectDisposedExceptionIf this stream has been disposed.

Definition at line 226 of file GZipStream.cs.

227  {
228  if (!CanWrite) throw new NotSupportedException();
229  if (_isDisposed) throw new ObjectDisposedException("GZipStream");
230 
231  int result = gzputc(_gzFile, (int)value);
232  if (result < 0)
233  throw new IOException();
234  }
static int gzputc(IntPtr gzFile, int c)
static int value
Definition: cmd_api.c:93

References DotZLib.GZipStream._gzFile, DotZLib.GZipStream._isDisposed, DotZLib.GZipStream.CanWrite, DotZLib.GZipStream.gzputc(), and value.

Member Data Documentation

◆ _gzFile

◆ _isDisposed

◆ _isWriting

bool DotZLib.GZipStream._isWriting
private

Definition at line 43 of file GZipStream.cs.

Referenced by DotZLib.GZipStream.GZipStream().

Property Documentation

◆ CanRead

override bool DotZLib.GZipStream.CanRead
get

Returns true of this stream can be read from, false otherwise

Definition at line 80 of file GZipStream.cs.

81  {
82  get
83  {
84  return !_isWriting;
85  }
86  }

Referenced by DotZLib.GZipStream.Read(), and DotZLib.GZipStream.ReadByte().

◆ CanSeek

override bool DotZLib.GZipStream.CanSeek
get

Returns false.

Definition at line 92 of file GZipStream.cs.

93  {
94  get
95  {
96  return false;
97  }
98  }

◆ CanWrite

override bool DotZLib.GZipStream.CanWrite
get

Returns true if this tsream is writeable, false otherwise

Definition at line 103 of file GZipStream.cs.

104  {
105  get
106  {
107  return _isWriting;
108  }
109  }

Referenced by DotZLib.GZipStream.Write(), and DotZLib.GZipStream.WriteByte().

◆ Length

override long DotZLib.GZipStream.Length
get

Gets the size of the stream. Not suppported.

In this implementation this property is not supported

Exceptions
NotSupportedExceptionAlways thrown

Definition at line 292 of file GZipStream.cs.

293  {
294  get
295  {
296  throw new NotSupportedException();
297  }
298  }

◆ Position

override long DotZLib.GZipStream.Position
getset

Gets/sets the current position in the GZipStream. Not suppported.

In this implementation this property is not supported

Exceptions
NotSupportedExceptionAlways thrown

Definition at line 275 of file GZipStream.cs.

276  {
277  get
278  {
279  throw new NotSupportedException();
280  }
281  set
282  {
283  throw new NotSupportedException();
284  }
285  }

The documentation for this class was generated from the following file: