| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,33 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <project name="DotZLib" default="build" basedir="./DotZLib"> | ||
| <description>A .Net wrapper library around ZLib1.dll</description> | ||
|
|
||
| <property name="nunit.location" value="c:/program files/NUnit V2.1/bin" /> | ||
| <property name="build.root" value="bin" /> | ||
|
|
||
| <property name="debug" value="true" /> | ||
| <property name="nunit" value="true" /> | ||
|
|
||
| <property name="build.folder" value="${build.root}/debug/" if="${debug}" /> | ||
| <property name="build.folder" value="${build.root}/release/" unless="${debug}" /> | ||
|
|
||
| <target name="clean" description="Remove all generated files"> | ||
| <delete dir="${build.root}" failonerror="false" /> | ||
| </target> | ||
|
|
||
| <target name="build" description="compiles the source code"> | ||
|
|
||
| <mkdir dir="${build.folder}" /> | ||
| <csc target="library" output="${build.folder}DotZLib.dll" debug="${debug}"> | ||
| <references basedir="${nunit.location}"> | ||
| <includes if="${nunit}" name="nunit.framework.dll" /> | ||
| </references> | ||
| <sources> | ||
| <includes name="*.cs" /> | ||
| <excludes name="UnitTests.cs" unless="${nunit}" /> | ||
| </sources> | ||
| <arg value="/d:nunit" if="${nunit}" /> | ||
| </csc> | ||
| </target> | ||
|
|
||
| </project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,21 @@ | ||
| Microsoft Visual Studio Solution File, Format Version 8.00 | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotZLib", "DotZLib\DotZLib.csproj", "{BB1EE0B1-1808-46CB-B786-949D91117FC5}" | ||
| ProjectSection(ProjectDependencies) = postProject | ||
| EndProjectSection | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfiguration) = preSolution | ||
| Debug = Debug | ||
| Release = Release | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfiguration) = postSolution | ||
| {BB1EE0B1-1808-46CB-B786-949D91117FC5}.Debug.ActiveCfg = Debug|.NET | ||
| {BB1EE0B1-1808-46CB-B786-949D91117FC5}.Debug.Build.0 = Debug|.NET | ||
| {BB1EE0B1-1808-46CB-B786-949D91117FC5}.Release.ActiveCfg = Release|.NET | ||
| {BB1EE0B1-1808-46CB-B786-949D91117FC5}.Release.Build.0 = Release|.NET | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityAddIns) = postSolution | ||
| EndGlobalSection | ||
| EndGlobal |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,58 +1,58 @@ | ||
| using System.Reflection; | ||
| using System.Runtime.CompilerServices; | ||
|
|
||
| // | ||
| // General Information about an assembly is controlled through the following | ||
| // set of attributes. Change these attribute values to modify the information | ||
| // associated with an assembly. | ||
| // | ||
| [assembly: AssemblyTitle("DotZLib")] | ||
| [assembly: AssemblyDescription(".Net bindings for ZLib compression dll 1.2.x")] | ||
| [assembly: AssemblyConfiguration("")] | ||
| [assembly: AssemblyCompany("Henrik Ravn")] | ||
| [assembly: AssemblyProduct("")] | ||
| [assembly: AssemblyCopyright("(c) 2004 by Henrik Ravn")] | ||
| [assembly: AssemblyTrademark("")] | ||
| [assembly: AssemblyCulture("")] | ||
|
|
||
| // | ||
| // Version information for an assembly consists of the following four values: | ||
| // | ||
| // Major Version | ||
| // Minor Version | ||
| // Build Number | ||
| // Revision | ||
| // | ||
| // You can specify all the values or you can default the Revision and Build Numbers | ||
| // by using the '*' as shown below: | ||
|
|
||
| [assembly: AssemblyVersion("1.0.*")] | ||
|
|
||
| // | ||
| // In order to sign your assembly you must specify a key to use. Refer to the | ||
| // Microsoft .NET Framework documentation for more information on assembly signing. | ||
| // | ||
| // Use the attributes below to control which key is used for signing. | ||
| // | ||
| // Notes: | ||
| // (*) If no key is specified, the assembly is not signed. | ||
| // (*) KeyName refers to a key that has been installed in the Crypto Service | ||
| // Provider (CSP) on your machine. KeyFile refers to a file which contains | ||
| // a key. | ||
| // (*) If the KeyFile and the KeyName values are both specified, the | ||
| // following processing occurs: | ||
| // (1) If the KeyName can be found in the CSP, that key is used. | ||
| // (2) If the KeyName does not exist and the KeyFile does exist, the key | ||
| // in the KeyFile is installed into the CSP and used. | ||
| // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. | ||
| // When specifying the KeyFile, the location of the KeyFile should be | ||
| // relative to the project output directory which is | ||
| // %Project Directory%\obj\<configuration>. For example, if your KeyFile is | ||
| // located in the project directory, you would specify the AssemblyKeyFile | ||
| // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] | ||
| // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework | ||
| // documentation for more information on this. | ||
| // | ||
| [assembly: AssemblyDelaySign(false)] | ||
| [assembly: AssemblyKeyFile("")] | ||
| [assembly: AssemblyKeyName("")] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,83 +1,83 @@ | ||
| // | ||
| // © 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; | ||
| using System.Diagnostics; | ||
|
|
||
| namespace DotZLib | ||
| { | ||
|
|
||
| /// <summary> | ||
| /// This class implements a circular buffer | ||
| /// </summary> | ||
| internal class CircularBuffer | ||
| { | ||
| #region Private data | ||
| private int _capacity; | ||
| private int _head; | ||
| private int _tail; | ||
| private int _size; | ||
| private byte[] _buffer; | ||
| #endregion | ||
|
|
||
| public CircularBuffer(int capacity) | ||
| { | ||
| Debug.Assert( capacity > 0 ); | ||
| _buffer = new byte[capacity]; | ||
| _capacity = capacity; | ||
| _head = 0; | ||
| _tail = 0; | ||
| _size = 0; | ||
| } | ||
|
|
||
| public int Size { get { return _size; } } | ||
|
|
||
| public int Put(byte[] source, int offset, int count) | ||
| { | ||
| Debug.Assert( count > 0 ); | ||
| int trueCount = Math.Min(count, _capacity - Size); | ||
| for (int i = 0; i < trueCount; ++i) | ||
| _buffer[(_tail+i) % _capacity] = source[offset+i]; | ||
| _tail += trueCount; | ||
| _tail %= _capacity; | ||
| _size += trueCount; | ||
| return trueCount; | ||
| } | ||
|
|
||
| public bool Put(byte b) | ||
| { | ||
| if (Size == _capacity) // no room | ||
| return false; | ||
| _buffer[_tail++] = b; | ||
| _tail %= _capacity; | ||
| ++_size; | ||
| return true; | ||
| } | ||
|
|
||
| public int Get(byte[] destination, int offset, int count) | ||
| { | ||
| int trueCount = Math.Min(count,Size); | ||
| for (int i = 0; i < trueCount; ++i) | ||
| destination[offset + i] = _buffer[(_head+i) % _capacity]; | ||
| _head += trueCount; | ||
| _head %= _capacity; | ||
| _size -= trueCount; | ||
| return trueCount; | ||
| } | ||
|
|
||
| public int Get() | ||
| { | ||
| if (Size == 0) | ||
| return -1; | ||
|
|
||
| int result = (int)_buffer[_head++ % _capacity]; | ||
| --_size; | ||
| return result; | ||
| } | ||
|
|
||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,198 +1,198 @@ | ||
| // | ||
| // © 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; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace DotZLib | ||
| { | ||
| /// <summary> | ||
| /// Implements the common functionality needed for all <see cref="Codec"/>s | ||
| /// </summary> | ||
| public abstract class CodecBase : Codec, IDisposable | ||
| { | ||
|
|
||
| #region Data members | ||
|
|
||
| /// <summary> | ||
| /// Instance of the internal zlib buffer structure that is | ||
| /// passed to all functions in the zlib dll | ||
| /// </summary> | ||
| internal ZStream _ztream = new ZStream(); | ||
|
|
||
| /// <summary> | ||
| /// True if the object instance has been disposed, false otherwise | ||
| /// </summary> | ||
| protected bool _isDisposed = false; | ||
|
|
||
| /// <summary> | ||
| /// The size of the internal buffers | ||
| /// </summary> | ||
| protected const int kBufferSize = 16384; | ||
|
|
||
| private byte[] _outBuffer = new byte[kBufferSize]; | ||
| private byte[] _inBuffer = new byte[kBufferSize]; | ||
|
|
||
| private GCHandle _hInput; | ||
| private GCHandle _hOutput; | ||
|
|
||
| private uint _checksum = 0; | ||
|
|
||
| #endregion | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <c>CodeBase</c> class. | ||
| /// </summary> | ||
| public CodecBase() | ||
| { | ||
| try | ||
| { | ||
| _hInput = GCHandle.Alloc(_inBuffer, GCHandleType.Pinned); | ||
| _hOutput = GCHandle.Alloc(_outBuffer, GCHandleType.Pinned); | ||
| } | ||
| catch (Exception) | ||
| { | ||
| CleanUp(false); | ||
| throw; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| #region Codec Members | ||
|
|
||
| /// <summary> | ||
| /// Occurs when more processed data are available. | ||
| /// </summary> | ||
| public event DataAvailableHandler DataAvailable; | ||
|
|
||
| /// <summary> | ||
| /// Fires the <see cref="DataAvailable"/> event | ||
| /// </summary> | ||
| protected void OnDataAvailable() | ||
| { | ||
| if (_ztream.total_out > 0) | ||
| { | ||
| if (DataAvailable != null) | ||
| DataAvailable( _outBuffer, 0, (int)_ztream.total_out); | ||
| 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> | ||
| /// <remarks>Adding data may, or may not, raise the <c>DataAvailable</c> event</remarks> | ||
| public void Add(byte[] data) | ||
| { | ||
| Add(data,0,data.Length); | ||
| } | ||
|
|
||
| /// <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> | ||
| /// <remarks>This must be implemented by a derived class</remarks> | ||
| public abstract void Add(byte[] data, int offset, int count); | ||
|
|
||
| /// <summary> | ||
| /// Finishes up any pending data that needs to be processed and handled. | ||
| /// </summary> | ||
| /// <remarks>This must be implemented by a derived class</remarks> | ||
| public abstract void Finish(); | ||
|
|
||
| /// <summary> | ||
| /// Gets the checksum of the data that has been added so far | ||
| /// </summary> | ||
| public uint Checksum { get { return _checksum; } } | ||
|
|
||
| #endregion | ||
|
|
||
| #region Destructor & IDisposable stuff | ||
|
|
||
| /// <summary> | ||
| /// Destroys this instance | ||
| /// </summary> | ||
| ~CodecBase() | ||
| { | ||
| CleanUp(false); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Releases any unmanaged resources and calls the <see cref="CleanUp()"/> method of the derived class | ||
| /// </summary> | ||
| public void Dispose() | ||
| { | ||
| CleanUp(true); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Performs any codec specific cleanup | ||
| /// </summary> | ||
| /// <remarks>This must be implemented by a derived class</remarks> | ||
| protected abstract void CleanUp(); | ||
|
|
||
| // performs the release of the handles and calls the derived CleanUp() | ||
| private void CleanUp(bool isDisposing) | ||
| { | ||
| if (!_isDisposed) | ||
| { | ||
| CleanUp(); | ||
| if (_hInput.IsAllocated) | ||
| _hInput.Free(); | ||
| if (_hOutput.IsAllocated) | ||
| _hOutput.Free(); | ||
|
|
||
| _isDisposed = true; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| #endregion | ||
|
|
||
| #region Helper methods | ||
|
|
||
| /// <summary> | ||
| /// Copies a number of bytes to the internal codec buffer - ready for processing | ||
| /// </summary> | ||
| /// <param name="data">The byte array that contains the data to copy</param> | ||
| /// <param name="startIndex">The index of the first byte to copy</param> | ||
| /// <param name="count">The number of bytes to copy from <c>data</c></param> | ||
| protected void copyInput(byte[] data, int startIndex, int count) | ||
| { | ||
| Array.Copy(data, startIndex, _inBuffer,0, count); | ||
| _ztream.next_in = _hInput.AddrOfPinnedObject(); | ||
| _ztream.total_in = 0; | ||
| _ztream.avail_in = (uint)count; | ||
|
|
||
| } | ||
|
|
||
| /// <summary> | ||
| /// Resets the internal output buffers to a known state - ready for processing | ||
| /// </summary> | ||
| protected void resetOutput() | ||
| { | ||
| _ztream.total_out = 0; | ||
| _ztream.avail_out = kBufferSize; | ||
| _ztream.next_out = _hOutput.AddrOfPinnedObject(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Updates the running checksum property | ||
| /// </summary> | ||
| /// <param name="newSum">The new checksum value</param> | ||
| protected void setChecksum(uint newSum) | ||
| { | ||
| _checksum = newSum; | ||
| } | ||
| #endregion | ||
|
|
||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,106 +1,106 @@ | ||
| // | ||
| // © 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; | ||
| using System.Diagnostics; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace DotZLib | ||
| { | ||
|
|
||
| /// <summary> | ||
| /// Implements a data compressor, using the deflate algorithm in the ZLib dll | ||
| /// </summary> | ||
| public sealed class Deflater : CodecBase | ||
| { | ||
| #region Dll imports | ||
| [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Ansi)] | ||
| private static extern int deflateInit_(ref ZStream sz, int level, string vs, int size); | ||
|
|
||
| [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] | ||
| private static extern int deflate(ref ZStream sz, int flush); | ||
|
|
||
| [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] | ||
| private static extern int deflateReset(ref ZStream sz); | ||
|
|
||
| [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] | ||
| private static extern int deflateEnd(ref ZStream sz); | ||
| #endregion | ||
|
|
||
| /// <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) | ||
| throw new 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> | ||
| public override void Add(byte[] data, int offset, int count) | ||
| { | ||
| if (data == null) throw new ArgumentNullException(); | ||
| if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException(); | ||
| if ((offset+count) > data.Length) throw new ArgumentException(); | ||
|
|
||
| int total = count; | ||
| int inputIndex = offset; | ||
| int err = 0; | ||
|
|
||
| while (err >= 0 && inputIndex < total) | ||
| { | ||
| copyInput(data, inputIndex, Math.Min(total - inputIndex, kBufferSize)); | ||
| while (err >= 0 && _ztream.avail_in > 0) | ||
| { | ||
| err = deflate(ref _ztream, (int)FlushTypes.None); | ||
| if (err == 0) | ||
| while (_ztream.avail_out == 0) | ||
| { | ||
| OnDataAvailable(); | ||
| err = deflate(ref _ztream, (int)FlushTypes.None); | ||
| } | ||
| inputIndex += (int)_ztream.total_in; | ||
| } | ||
| } | ||
| setChecksum( _ztream.adler ); | ||
| } | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Finishes up any pending data that needs to be processed and handled. | ||
| /// </summary> | ||
| public override void Finish() | ||
| { | ||
| int err; | ||
| do | ||
| { | ||
| err = deflate(ref _ztream, (int)FlushTypes.Finish); | ||
| OnDataAvailable(); | ||
| } | ||
| while (err == 0); | ||
| setChecksum( _ztream.adler ); | ||
| deflateReset(ref _ztream); | ||
| resetOutput(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Closes the internal zlib deflate stream | ||
| /// </summary> | ||
| protected override void CleanUp() { deflateEnd(ref _ztream); } | ||
|
|
||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,141 +1,141 @@ | ||
| <VisualStudioProject> | ||
| <CSHARP | ||
| ProjectType = "Local" | ||
| ProductVersion = "7.10.3077" | ||
| SchemaVersion = "2.0" | ||
| ProjectGuid = "{BB1EE0B1-1808-46CB-B786-949D91117FC5}" | ||
| > | ||
| <Build> | ||
| <Settings | ||
| ApplicationIcon = "" | ||
| AssemblyKeyContainerName = "" | ||
| AssemblyName = "DotZLib" | ||
| AssemblyOriginatorKeyFile = "" | ||
| DefaultClientScript = "JScript" | ||
| DefaultHTMLPageLayout = "Grid" | ||
| DefaultTargetSchema = "IE50" | ||
| DelaySign = "false" | ||
| OutputType = "Library" | ||
| PreBuildEvent = "" | ||
| PostBuildEvent = "" | ||
| RootNamespace = "DotZLib" | ||
| RunPostBuildEvent = "OnBuildSuccess" | ||
| StartupObject = "" | ||
| > | ||
| <Config | ||
| Name = "Debug" | ||
| AllowUnsafeBlocks = "false" | ||
| BaseAddress = "285212672" | ||
| CheckForOverflowUnderflow = "false" | ||
| ConfigurationOverrideFile = "" | ||
| DefineConstants = "DEBUG;TRACE" | ||
| DocumentationFile = "docs\DotZLib.xml" | ||
| DebugSymbols = "true" | ||
| FileAlignment = "4096" | ||
| IncrementalBuild = "false" | ||
| NoStdLib = "false" | ||
| NoWarn = "1591" | ||
| Optimize = "false" | ||
| OutputPath = "bin\Debug\" | ||
| RegisterForComInterop = "false" | ||
| RemoveIntegerChecks = "false" | ||
| TreatWarningsAsErrors = "false" | ||
| WarningLevel = "4" | ||
| /> | ||
| <Config | ||
| Name = "Release" | ||
| AllowUnsafeBlocks = "false" | ||
| BaseAddress = "285212672" | ||
| CheckForOverflowUnderflow = "false" | ||
| ConfigurationOverrideFile = "" | ||
| DefineConstants = "TRACE" | ||
| DocumentationFile = "docs\DotZLib.xml" | ||
| DebugSymbols = "false" | ||
| FileAlignment = "4096" | ||
| IncrementalBuild = "false" | ||
| NoStdLib = "false" | ||
| NoWarn = "" | ||
| Optimize = "true" | ||
| OutputPath = "bin\Release\" | ||
| RegisterForComInterop = "false" | ||
| RemoveIntegerChecks = "false" | ||
| TreatWarningsAsErrors = "false" | ||
| WarningLevel = "4" | ||
| /> | ||
| </Settings> | ||
| <References> | ||
| <Reference | ||
| Name = "System" | ||
| AssemblyName = "System" | ||
| HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.dll" | ||
| /> | ||
| <Reference | ||
| Name = "System.Data" | ||
| AssemblyName = "System.Data" | ||
| HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Data.dll" | ||
| /> | ||
| <Reference | ||
| Name = "System.XML" | ||
| AssemblyName = "System.Xml" | ||
| HintPath = "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.XML.dll" | ||
| /> | ||
| <Reference | ||
| Name = "nunit.framework" | ||
| AssemblyName = "nunit.framework" | ||
| HintPath = "E:\apps\NUnit V2.1\\bin\nunit.framework.dll" | ||
| AssemblyFolderKey = "hklm\dn\nunit.framework" | ||
| /> | ||
| </References> | ||
| </Build> | ||
| <Files> | ||
| <Include> | ||
| <File | ||
| RelPath = "AssemblyInfo.cs" | ||
| SubType = "Code" | ||
| BuildAction = "Compile" | ||
| /> | ||
| <File | ||
| RelPath = "ChecksumImpl.cs" | ||
| SubType = "Code" | ||
| BuildAction = "Compile" | ||
| /> | ||
| <File | ||
| RelPath = "CircularBuffer.cs" | ||
| SubType = "Code" | ||
| BuildAction = "Compile" | ||
| /> | ||
| <File | ||
| RelPath = "CodecBase.cs" | ||
| SubType = "Code" | ||
| BuildAction = "Compile" | ||
| /> | ||
| <File | ||
| RelPath = "Deflater.cs" | ||
| SubType = "Code" | ||
| BuildAction = "Compile" | ||
| /> | ||
| <File | ||
| RelPath = "DotZLib.cs" | ||
| SubType = "Code" | ||
| BuildAction = "Compile" | ||
| /> | ||
| <File | ||
| RelPath = "GZipStream.cs" | ||
| SubType = "Code" | ||
| BuildAction = "Compile" | ||
| /> | ||
| <File | ||
| RelPath = "Inflater.cs" | ||
| SubType = "Code" | ||
| BuildAction = "Compile" | ||
| /> | ||
| <File | ||
| RelPath = "UnitTests.cs" | ||
| SubType = "Code" | ||
| BuildAction = "Compile" | ||
| /> | ||
| </Include> | ||
| </Files> | ||
| </CSHARP> | ||
| </VisualStudioProject> | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,105 +1,105 @@ | ||
| // | ||
| // © 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; | ||
| using System.Diagnostics; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace DotZLib | ||
| { | ||
|
|
||
| /// <summary> | ||
| /// Implements a data decompressor, using the inflate algorithm in the ZLib dll | ||
| /// </summary> | ||
| public class Inflater : CodecBase | ||
| { | ||
| #region Dll imports | ||
| [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Ansi)] | ||
| private static extern int inflateInit_(ref ZStream sz, string vs, int size); | ||
|
|
||
| [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] | ||
| private static extern int inflate(ref ZStream sz, int flush); | ||
|
|
||
| [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] | ||
| private static extern int inflateReset(ref ZStream sz); | ||
|
|
||
| [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] | ||
| private static extern int inflateEnd(ref ZStream sz); | ||
| #endregion | ||
|
|
||
| /// <summary> | ||
| /// Constructs an new instance of the <c>Inflater</c> | ||
| /// </summary> | ||
| public Inflater() : base() | ||
| { | ||
| int retval = inflateInit_(ref _ztream, Info.Version, Marshal.SizeOf(_ztream)); | ||
| if (retval != 0) | ||
| throw new ZLibException(retval, "Could not initialize inflater"); | ||
|
|
||
| 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> | ||
| public override void Add(byte[] data, int offset, int count) | ||
| { | ||
| if (data == null) throw new ArgumentNullException(); | ||
| if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException(); | ||
| if ((offset+count) > data.Length) throw new ArgumentException(); | ||
|
|
||
| int total = count; | ||
| int inputIndex = offset; | ||
| int err = 0; | ||
|
|
||
| while (err >= 0 && inputIndex < total) | ||
| { | ||
| copyInput(data, inputIndex, Math.Min(total - inputIndex, kBufferSize)); | ||
| err = inflate(ref _ztream, (int)FlushTypes.None); | ||
| if (err == 0) | ||
| while (_ztream.avail_out == 0) | ||
| { | ||
| OnDataAvailable(); | ||
| err = inflate(ref _ztream, (int)FlushTypes.None); | ||
| } | ||
|
|
||
| inputIndex += (int)_ztream.total_in; | ||
| } | ||
| setChecksum( _ztream.adler ); | ||
| } | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Finishes up any pending data that needs to be processed and handled. | ||
| /// </summary> | ||
| public override void Finish() | ||
| { | ||
| int err; | ||
| do | ||
| { | ||
| err = inflate(ref _ztream, (int)FlushTypes.Finish); | ||
| OnDataAvailable(); | ||
| } | ||
| while (err == 0); | ||
| setChecksum( _ztream.adler ); | ||
| inflateReset(ref _ztream); | ||
| resetOutput(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Closes the internal zlib inflate stream | ||
| /// </summary> | ||
| protected override void CleanUp() { inflateEnd(ref _ztream); } | ||
|
|
||
|
|
||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,23 @@ | ||
| Boost Software License - Version 1.0 - August 17th, 2003 | ||
|
|
||
| Permission is hereby granted, free of charge, to any person or organization | ||
| obtaining a copy of the software and accompanying documentation covered by | ||
| this license (the "Software") to use, reproduce, display, distribute, | ||
| execute, and transmit the Software, and to prepare derivative works of the | ||
| Software, and to permit third-parties to whom the Software is furnished to | ||
| do so, all subject to the following: | ||
|
|
||
| The copyright notices in the Software and this entire statement, including | ||
| the above license grant, this restriction and the following disclaimer, | ||
| must be included in all copies of the Software, in whole or in part, and | ||
| all derivative works of the Software, unless such copies or derivative | ||
| works are solely in the form of machine-executable object code generated by | ||
| a source language processor. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT | ||
| SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE | ||
| FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, | ||
| ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
| DEALINGS IN THE SOFTWARE. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,58 +1,58 @@ | ||
| This directory contains a .Net wrapper class library for the ZLib1.dll | ||
|
|
||
| The wrapper includes support for inflating/deflating memory buffers, | ||
| .Net streaming wrappers for the gz streams part of zlib, and wrappers | ||
| for the checksum parts of zlib. See DotZLib/UnitTests.cs for examples. | ||
|
|
||
| Directory structure: | ||
| -------------------- | ||
|
|
||
| LICENSE_1_0.txt - License file. | ||
| readme.txt - This file. | ||
| DotZLib.chm - Class library documentation | ||
| DotZLib.build - NAnt build file | ||
| DotZLib.sln - Microsoft Visual Studio 2003 solution file | ||
|
|
||
| DotZLib\*.cs - Source files for the class library | ||
|
|
||
| Unit tests: | ||
| ----------- | ||
| The file DotZLib/UnitTests.cs contains unit tests for use with NUnit 2.1 or higher. | ||
| To include unit tests in the build, define nunit before building. | ||
|
|
||
|
|
||
| Build instructions: | ||
| ------------------- | ||
|
|
||
| 1. Using Visual Studio.Net 2003: | ||
| Open DotZLib.sln in VS.Net and build from there. Output file (DotZLib.dll) | ||
| will be found ./DotZLib/bin/release or ./DotZLib/bin/debug, depending on | ||
| you are building the release or debug version of the library. Check | ||
| DotZLib/UnitTests.cs for instructions on how to include unit tests in the | ||
| build. | ||
|
|
||
| 2. Using NAnt: | ||
| Open a command prompt with access to the build environment and run nant | ||
| in the same directory as the DotZLib.build file. | ||
| You can define 2 properties on the nant command-line to control the build: | ||
| debug={true|false} to toggle between release/debug builds (default=true). | ||
| nunit={true|false} to include or exclude unit tests (default=true). | ||
| Also the target clean will remove binaries. | ||
| Output file (DotZLib.dll) will be found in either ./DotZLib/bin/release | ||
| or ./DotZLib/bin/debug, depending on whether you are building the release | ||
| or debug version of the library. | ||
|
|
||
| Examples: | ||
| nant -D:debug=false -D:nunit=false | ||
| will build a release mode version of the library without unit tests. | ||
| nant | ||
| will build a debug version of the library with unit tests | ||
| nant clean | ||
| will remove all previously built files. | ||
|
|
||
|
|
||
| --------------------------------- | ||
| Copyright (c) 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) |