//
// � Copyright Henrik Ravn 2004
//
// Use, modification and distribution are subject to the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
using System;
namespace DotZLib
{
/// <summary>
/// Defines constants for the various flush types used with zlib
/// </summary>
internal enum FlushTypes
{
}
// internal mapping of the zlib zstream structure for marshalling
internal struct ZStream
{
public uint avail_in;
public uint total_in;
public uint avail_out;
public uint total_out;
string msg;
uint state;
uint zalloc;
uint zfree;
uint opaque;
int data_type;
public uint adler;
uint reserved;
}
/// <summary>
/// Defines constants for the available compression levels in zlib
/// </summary>
public enum CompressLevel : int
{
/// <summary>
/// The default compression level with a reasonable compromise between compression and speed
/// </summary>
Default = -1,
/// <summary>
/// No compression at all. The data are passed straight through.
/// </summary>
None = 0,
/// <summary>
/// The maximum compression rate available.
/// </summary>
Best = 9,
/// <summary>
/// The fastest available compression level.
/// </summary>
Fastest = 1
}
/// <summary>
/// The exception that is thrown when an error occurs on the zlib dll
/// </summary>
public class ZLibException : ApplicationException
{
/// <summary>
/// Initializes a new instance of the <see cref="ZLibException"/> class with a specified
/// error message and error code
/// </summary>
/// <param name="errorCode">The zlib error code that caused the exception</param>
/// <param name="msg">A message that (hopefully) describes the error</param>
public ZLibException(int errorCode, string msg) : base(String.Format("ZLib error {0} {1}", errorCode, msg))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ZLibException"/> class with a specified
/// error code
/// </summary>
/// <param name="errorCode">The zlib error code that caused the exception</param>
{
}
}
/// <summary>
/// Declares methods and properties that enables a running checksum to be calculated
/// </summary>
public interface ChecksumGenerator
{
/// <summary>
/// Gets the current value of the checksum
/// </summary>
uint Value { get; }
/// <summary>
/// Clears the current checksum to 0
/// </summary>
void Reset();
/// <summary>
/// Updates the current checksum with an array of bytes
/// </summary>
/// <param name="data">The data to update the checksum with</param>
/// <summary>
/// Updates the current checksum with part of an array of bytes
/// </summary>
/// <param name="data">The data to update the checksum with</param>
/// <param name="offset">Where in <c>data</c> to start updating</param>
/// <param name="count">The number of bytes from <c>data</c> to use</param>
/// <exception cref="ArgumentException">The sum of offset and count is larger than the length of <c>data</c></exception>
/// <exception cref="ArgumentNullException"><c>data</c> is a null reference</exception>
/// <exception cref="ArgumentOutOfRangeException">Offset or count is negative.</exception>
/// <summary>
/// Updates the current checksum with the data from a string
/// </summary>
/// <param name="data">The string to update the checksum with</param>
/// <remarks>The characters in the string are converted by the UTF-8 encoding</remarks>
/// <summary>
/// Updates the current checksum with the data from a string, using a specific encoding
/// </summary>
/// <param name="data">The string to update the checksum with</param>
/// <param name="encoding">The encoding to use</param>
}
/// <summary>
/// Represents the method that will be called from a codec when new data
/// are available.
/// </summary>
/// <paramref name="data">The byte array containing the processed data</paramref>
/// <paramref name="startIndex">The index of the first processed byte in <c>data</c></paramref>
/// <paramref name="count">The number of processed bytes available</paramref>
/// <remarks>On return from this method, the data may be overwritten, so grab it while you can.
/// You cannot assume that startIndex will be zero.
/// </remarks>
/// <summary>
/// Declares methods and events for implementing compressors/decompressors
/// </summary>
public interface Codec
{
/// <summary>
/// Occurs when more processed data are available.
/// </summary>
/// <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>
/// <remarks>Adding data may, or may not, raise the <c>DataAvailable</c> event</remarks>
/// <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>
/// <summary>
/// Finishes up any pending data that needs to be processed and handled.
/// </summary>
void Finish();
/// <summary>
/// Gets the checksum of the data that has been added so far
/// </summary>
uint Checksum { get; }
}
/// <summary>
/// Encapsulates general information about the ZLib library
/// </summary>
public class Info
{
private static extern uint zlibCompileFlags();
private static extern string zlibVersion();
private uint _flags;
// helper function that unpacks a bitsize mask
{
switch (bits)
{
case 0: return 16;
case 1: return 32;
case 2: return 64;
}
return -1;
}
/// <summary>
/// Constructs an instance of the <c>Info</c> class.
/// </summary>
public Info()
{
_flags = zlibCompileFlags();
}
/// <summary>
/// True if the library is compiled with debug info
/// </summary>
/// <summary>
/// True if the library is compiled with assembly optimizations
/// </summary>
/// <summary>
/// Gets the size of the unsigned int that was compiled into Zlib
/// </summary>
/// <summary>
/// Gets the size of the unsigned long that was compiled into Zlib
/// </summary>
/// <summary>
/// Gets the size of the pointers that were compiled into Zlib
/// </summary>
/// <summary>
/// Gets the size of the z_off_t type that was compiled into Zlib
/// </summary>
/// <summary>
/// Gets the version of ZLib as a string, e.g. "1.2.1"
/// </summary>
public static string Version { get { return zlibVersion(); } }
}
}