using System; using System.Diagnostics; using System.Runtime.InteropServices;
namespace DotZLib
{
/// <summary> /// Implements a data compressor, using the deflate algorithm in the ZLib dll /// </summary> publicsealedclass Deflater : CodecBase
{ #region Dll imports
[DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Ansi)] privatestaticexternint deflateInit_(ref ZStream sz, int level, string vs, int size);
[DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] privatestaticexternint deflate(ref ZStream sz, int flush);
/// <summary> /// Constructs an new instance of the <c>Deflater</c> /// </summary> /// <param name="level">The compression level to use for this <c>Deflater</c></param> public Deflater(CompressLevel level) : base()
{ int retval = deflateInit_(ref _ztream, (int)level, Info.Version, Marshal.SizeOf(_ztream)); if (retval != 0) thrownew ZLibException(retval, "Could not initialize deflater");
resetOutput();
}
/// <summary> /// Adds more data to the codec to be processed. /// </summary> /// <param name="data">Byte array containing the data to be added to the codec</param> /// <param name="offset">The index of the first byte to add from <c>data</c></param> /// <param name="count">The number of bytes to add</param> /// <remarks>Adding data may, or may not, raise the <c>DataAvailable</c> event</remarks> publicoverridevoidAdd(byte[] data, int offset, int count)
{ if (data == null) thrownew ArgumentNullException(); if (offset < 0 || count < 0) thrownew ArgumentOutOfRangeException(); if ((offset+count) > data.Length) thrownew ArgumentException();
int total = count; int inputIndex = offset; int err = 0;
/// <summary> /// Finishes up any pending data that needs to be processed and handled. /// </summary> publicoverridevoid Finish()
{ int err; do
{
err = deflate(ref _ztream, (int)FlushTypes.Finish);
OnDataAvailable();
} while (err == 0);
setChecksum( _ztream.adler );
deflateReset(ref _ztream);
resetOutput();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.