10 using System.Runtime.InteropServices;
21 [DllImport(
"ZLIB1.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Ansi)]
22 private static extern int deflateInit_(
ref ZStream sz,
int level,
string vs,
int size);
24 [DllImport(
"ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
25 private static extern int deflate(
ref ZStream sz,
int flush);
27 [DllImport(
"ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
28 private static extern int deflateReset(
ref ZStream sz);
30 [DllImport(
"ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
31 private static extern int deflateEnd(
ref ZStream sz);
40 int retval = deflateInit_(
ref _ztream, (
int)level,
Info.
Version, Marshal.SizeOf(_ztream));
42 throw new ZLibException(retval,
"Could not initialize deflater");
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();
64 while (err >= 0 && inputIndex < total)
67 while (err >= 0 && _ztream.avail_in > 0)
69 err = deflate(
ref _ztream, (
int)FlushTypes.None);
71 while (_ztream.avail_out == 0)
74 err = deflate(
ref _ztream, (
int)FlushTypes.None);
76 inputIndex += (
int)_ztream.total_in;
91 err = deflate(
ref _ztream, (
int)FlushTypes.Finish);
96 deflateReset(
ref _ztream);
103 protected override void CleanUp() { deflateEnd(
ref _ztream); }
void setChecksum(uint newSum)
Updates the running checksum property
Implements the common functionality needed for all Codecs
override void Add(byte[] data, int offset, int count)
Adds more data to the codec to be processed.
Implements a data compressor, using the deflate algorithm in the ZLib dll
void copyInput(byte[] data, int startIndex, int count)
Copies a number of bytes to the internal codec buffer - ready for proccesing
GLsizei GLsizei GLenum GLenum const GLvoid * data
static string Version
Gets the version of ZLib as a string, e.g.
void OnDataAvailable()
Fires the DataAvailable event
override void Finish()
Finishes up any pending data that needs to be processed and handled.
void resetOutput()
Resets the internal output buffers to a known state - ready for processing
override void CleanUp()
Closes the internal zlib deflate stream
GLuint GLuint GLsizei count
Encapsulates general information about the ZLib library
CompressLevel
Defines constants for the available compression levels in zlib
const int kBufferSize
The size of the internal buffers
Deflater(CompressLevel level)
Constructs an new instance of the Deflater
The exception that is thrown when an error occurs on the zlib dll