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

Implements a data compressor, using the deflate algorithm in the ZLib dll More...

Inheritance diagram for DotZLib.Deflater:
DotZLib.CodecBase DotZLib.Codec

Public Member Functions

 Deflater (CompressLevel level)
 Constructs an new instance of the Deflater More...
 
override void Add (byte[] data, int offset, int count)
 Adds more data to the codec to be processed. More...
 
override void Finish ()
 Finishes up any pending data that needs to be processed and handled. More...
 
- Public Member Functions inherited from DotZLib.CodecBase
 CodecBase ()
 Initializes a new instance of the CodeBase class. More...
 
void Add (byte[] data)
 Adds more data to the codec to be processed. More...
 
void Dispose ()
 Releases any unmanaged resources and calls the CleanUp() method of the derived class More...
 

Protected Member Functions

override void CleanUp ()
 Closes the internal zlib deflate stream More...
 
- Protected Member Functions inherited from DotZLib.CodecBase
void OnDataAvailable ()
 Fires the DataAvailable event More...
 
void copyInput (byte[] data, int startIndex, int count)
 Copies a number of bytes to the internal codec buffer - ready for proccesing More...
 
void resetOutput ()
 Resets the internal output buffers to a known state - ready for processing More...
 
void setChecksum (uint newSum)
 Updates the running checksum property More...
 

Private Member Functions

static int deflateInit_ (ref ZStream sz, int level, string vs, int size)
 
static int deflate (ref ZStream sz, int flush)
 
static int deflateReset (ref ZStream sz)
 
static int deflateEnd (ref ZStream sz)
 

Additional Inherited Members

- Protected Attributes inherited from DotZLib.CodecBase
bool _isDisposed = false
 True if the object instance has been disposed, false otherwise More...
 
- Static Protected Attributes inherited from DotZLib.CodecBase
const int kBufferSize = 16384
 The size of the internal buffers More...
 
- Package Attributes inherited from DotZLib.CodecBase
ZStream _ztream = new ZStream()
 Instance of the internal zlib buffer structure that is passed to all functions in the zlib dll More...
 
- Properties inherited from DotZLib.CodecBase
uint Checksum [get]
 Gets the checksum of the data that has been added so far More...
 
- Properties inherited from DotZLib.Codec
uint Checksum [get]
 Gets the checksum of the data that has been added so far More...
 
- Events inherited from DotZLib.CodecBase
DataAvailableHandler DataAvailable
 Occurs when more processed data are available. More...
 
- Events inherited from DotZLib.Codec
DataAvailableHandler DataAvailable
 Occurs when more processed data are available. More...
 

Detailed Description

Implements a data compressor, using the deflate algorithm in the ZLib dll

Definition at line 18 of file Deflater.cs.

Constructor & Destructor Documentation

◆ Deflater()

DotZLib.Deflater.Deflater ( CompressLevel  level)
inline

Constructs an new instance of the Deflater

Parameters
levelThe compression level to use for this Deflater

Definition at line 38 of file Deflater.cs.

38  : base()
39  {
40  int retval = deflateInit_(ref _ztream, (int)level, Info.Version, Marshal.SizeOf(_ztream));
41  if (retval != 0)
42  throw new ZLibException(retval, "Could not initialize deflater");
43 
44  resetOutput();
45  }
ZStream _ztream
Instance of the internal zlib buffer structure that is passed to all functions in the zlib dll
Definition: CodecBase.cs:25
void resetOutput()
Resets the internal output buffers to a known state - ready for processing
Definition: CodecBase.cs:180
static int deflateInit_(ref ZStream sz, int level, string vs, int size)
static int level
Definition: vmenus.c:2424

References DotZLib.CodecBase._ztream, DotZLib.Deflater.deflateInit_(), level, DotZLib.CodecBase.resetOutput(), and DotZLib.Info.Version.

Member Function Documentation

◆ Add()

override void DotZLib.Deflater.Add ( byte[]  data,
int  offset,
int  count 
)
inlinevirtual

Adds more data to the codec to be processed.

Parameters
dataByte array containing the data to be added to the codec
offsetThe index of the first byte to add from data
countThe number of bytes to add

Adding data may, or may not, raise the DataAvailable event

Implements DotZLib.CodecBase.

Definition at line 54 of file Deflater.cs.

55  {
56  if (data == null) throw new ArgumentNullException();
57  if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException();
58  if ((offset+count) > data.Length) throw new ArgumentException();
59 
60  int total = count;
61  int inputIndex = offset;
62  int err = 0;
63 
64  while (err >= 0 && inputIndex < total)
65  {
66  copyInput(data, inputIndex, Math.Min(total - inputIndex, kBufferSize));
67  while (err >= 0 && _ztream.avail_in > 0)
68  {
69  err = deflate(ref _ztream, (int)FlushTypes.None);
70  if (err == 0)
71  while (_ztream.avail_out == 0)
72  {
74  err = deflate(ref _ztream, (int)FlushTypes.None);
75  }
76  inputIndex += (int)_ztream.total_in;
77  }
78  }
80  }
static bool err
Definition: armass.c:435
void OnDataAvailable()
Fires the DataAvailable event
Definition: CodecBase.cs:75
void setChecksum(uint newSum)
Updates the running checksum property
Definition: CodecBase.cs:191
const int kBufferSize
The size of the internal buffers
Definition: CodecBase.cs:35
void copyInput(byte[] data, int startIndex, int count)
Copies a number of bytes to the internal codec buffer - ready for proccesing
Definition: CodecBase.cs:168
static int deflate(ref ZStream sz, int flush)
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
FlushTypes
Defines constants for the various flush types used with zlib
Definition: DotZLib.cs:23
static int
Definition: sfsocketcall.h:114
uint avail_in
Definition: DotZLib.cs:33
uint avail_out
Definition: DotZLib.cs:37
uint total_in
Definition: DotZLib.cs:34

References DotZLib.CodecBase._ztream, DotZLib.ZStream.adler, DotZLib.ZStream.avail_in, DotZLib.ZStream.avail_out, DotZLib.CodecBase.copyInput(), count, DotZLib.Deflater.deflate(), err, int, DotZLib.CodecBase.kBufferSize, DotZLib.CodecBase.OnDataAvailable(), DotZLib.CodecBase.setChecksum(), and DotZLib.ZStream.total_in.

◆ CleanUp()

override void DotZLib.Deflater.CleanUp ( )
inlineprotectedvirtual

Closes the internal zlib deflate stream

Implements DotZLib.CodecBase.

Definition at line 103 of file Deflater.cs.

103 { deflateEnd(ref _ztream); }
static int deflateEnd(ref ZStream sz)

References DotZLib.CodecBase._ztream, and DotZLib.Deflater.deflateEnd().

◆ deflate()

static int DotZLib.Deflater.deflate ( ref ZStream  sz,
int  flush 
)
private

◆ deflateEnd()

static int DotZLib.Deflater.deflateEnd ( ref ZStream  sz)
private

◆ deflateInit_()

static int DotZLib.Deflater.deflateInit_ ( ref ZStream  sz,
int  level,
string  vs,
int  size 
)
private

◆ deflateReset()

static int DotZLib.Deflater.deflateReset ( ref ZStream  sz)
private

Referenced by DotZLib.Deflater.Finish().

◆ Finish()

override void DotZLib.Deflater.Finish ( )
inlinevirtual

Finishes up any pending data that needs to be processed and handled.

Implements DotZLib.CodecBase.

Definition at line 86 of file Deflater.cs.

87  {
88  int err;
89  do
90  {
91  err = deflate(ref _ztream, (int)FlushTypes.Finish);
93  }
94  while (err == 0);
96  deflateReset(ref _ztream);
97  resetOutput();
98  }
static int deflateReset(ref ZStream sz)

References DotZLib.CodecBase._ztream, DotZLib.ZStream.adler, DotZLib.Deflater.deflate(), DotZLib.Deflater.deflateReset(), err, DotZLib.CodecBase.OnDataAvailable(), DotZLib.CodecBase.resetOutput(), and DotZLib.CodecBase.setChecksum().


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