diff --git a/Adler32.cs b/Adler32.cs
index c629111..9d580f3 100755
--- a/Adler32.cs
+++ b/Adler32.cs
@@ -3,9 +3,7 @@
// All rights reserved.
// license: see LICENSE for more details.
-[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Els_kom_Core", AllInternalsVisible = true)]
-
-namespace Els_kom.Compression.Libs.Zlib
+namespace Elskom.Generic.Libs
{
internal sealed class Adler32
{
diff --git a/Deflate.cs b/Deflate.cs
index dbdc846..9be2ca5 100755
--- a/Deflate.cs
+++ b/Deflate.cs
@@ -3,7 +3,7 @@
// All rights reserved.
// license: see LICENSE for more details.
-namespace Els_kom.Compression.Libs.Zlib
+namespace Elskom.Generic.Libs
{
using System;
diff --git a/InfBlocks.cs b/InfBlocks.cs
index 8d54d45..1ab197c 100755
--- a/InfBlocks.cs
+++ b/InfBlocks.cs
@@ -3,7 +3,7 @@
// All rights reserved.
// license: see LICENSE for more details.
-namespace Els_kom.Compression.Libs.Zlib
+namespace Elskom.Generic.Libs
{
using System;
diff --git a/InfCodes.cs b/InfCodes.cs
index 8a0eb2b..bbbbb2b 100755
--- a/InfCodes.cs
+++ b/InfCodes.cs
@@ -3,7 +3,7 @@
// All rights reserved.
// license: see LICENSE for more details.
-namespace Els_kom.Compression.Libs.Zlib
+namespace Elskom.Generic.Libs
{
using System;
diff --git a/InfTree.cs b/InfTree.cs
index a06c59f..37b0a18 100755
--- a/InfTree.cs
+++ b/InfTree.cs
@@ -3,7 +3,7 @@
// All rights reserved.
// license: see LICENSE for more details.
-namespace Els_kom.Compression.Libs.Zlib
+namespace Elskom.Generic.Libs
{
using System;
diff --git a/Inflate.cs b/Inflate.cs
index 35368bc..9ff06d6 100755
--- a/Inflate.cs
+++ b/Inflate.cs
@@ -3,7 +3,7 @@
// All rights reserved.
// license: see LICENSE for more details.
-namespace Els_kom.Compression.Libs.Zlib
+namespace Elskom.Generic.Libs
{
internal sealed class Inflate
{
diff --git a/MemoryZlib.cs b/MemoryZlib.cs
new file mode 100644
index 0000000..74485e0
--- /dev/null
+++ b/MemoryZlib.cs
@@ -0,0 +1,118 @@
+// Copyright (c) 2014-2018, Els_kom org.
+// https://github.com/Elskom/
+// All rights reserved.
+// license: MIT, see LICENSE for more details.
+
+namespace Elskom.Generic.Libs
+{
+ using System.IO;
+
+ ///
+ /// Zlib Memory Compression and Decompression Helper Class.
+ ///
+ public static class MemoryZlib
+ {
+ ///
+ /// Compresses data using the default compression level.
+ ///
+ /// The original input data.
+ /// The compressed output data.
+ /// The output adler32 of the data.
+ /// Thrown when the stream Errors in any way.
+ public static void CompressData(byte[] inData, out byte[] outData, out int adler32)
+ => CompressData(inData, out outData, ZlibConst.ZDEFAULTCOMPRESSION, out adler32);
+
+ ///
+ /// Compresses data using the default compression level.
+ ///
+ /// The original input data.
+ /// The compressed output data.
+ /// Thrown when the stream Errors in any way.
+ public static void CompressData(byte[] inData, out byte[] outData)
+ => CompressData(inData, out outData, ZlibConst.ZDEFAULTCOMPRESSION);
+
+ ///
+ /// Compresses data using an specific compression level.
+ ///
+ /// The original input data.
+ /// The compressed output data.
+ /// The compression level to use.
+ /// Thrown when the stream Errors in any way.
+ // discard returned adler32. The caller does not want it.
+ public static void CompressData(byte[] inData, out byte[] outData, int level)
+ => CompressData(inData, out outData, level, out var adler32);
+
+ ///
+ /// Compresses data using an specific compression level.
+ ///
+ /// The original input data.
+ /// The compressed output data.
+ /// The compression level to use.
+ /// The output adler32 of the data.
+ /// Thrown when the stream Errors in any way.
+ public static void CompressData(byte[] inData, out byte[] outData, int level, out int adler32)
+ {
+ using (var outMemoryStream = new MemoryStream())
+ using (var outZStream = new ZOutputStream(outMemoryStream, level))
+ using (Stream inMemoryStream = new MemoryStream(inData))
+ {
+ try
+ {
+ inMemoryStream.CopyTo(outZStream);
+ }
+ catch (ZStreamException)
+ {
+ // the compression or decompression failed.
+ }
+
+ outZStream.Flush();
+ try
+ {
+ outZStream.Finish();
+ }
+ catch (ZStreamException ex)
+ {
+ throw new NotPackableException("Compression Failed.", ex);
+ }
+
+ outData = outMemoryStream.ToArray();
+ adler32 = (int)(outZStream.Z.Adler & 0xffff);
+ }
+ }
+
+ ///
+ /// Decompresses data.
+ ///
+ /// The compressed input data.
+ /// The decompressed output data.
+ /// Thrown when the stream Errors in any way.
+ public static void DecompressData(byte[] inData, out byte[] outData)
+ {
+ using (var outMemoryStream = new MemoryStream())
+ using (var outZStream = new ZOutputStream(outMemoryStream))
+ using (Stream inMemoryStream = new MemoryStream(inData))
+ {
+ try
+ {
+ inMemoryStream.CopyTo(outZStream);
+ }
+ catch (ZStreamException)
+ {
+ // the compression or decompression failed.
+ }
+
+ outZStream.Flush();
+ try
+ {
+ outZStream.Finish();
+ }
+ catch (ZStreamException ex)
+ {
+ throw new NotUnpackableException("Decompression Failed.", ex);
+ }
+
+ outData = outMemoryStream.ToArray();
+ }
+ }
+ }
+}
diff --git a/NotPackableException.cs b/NotPackableException.cs
new file mode 100644
index 0000000..fa60263
--- /dev/null
+++ b/NotPackableException.cs
@@ -0,0 +1,44 @@
+// Copyright (c) 2014-2018, Els_kom org.
+// https://github.com/Elskom/
+// All rights reserved.
+// license: MIT, see LICENSE for more details.
+
+namespace Elskom.Generic.Libs
+{
+ using System;
+ using System.IO;
+
+ ///
+ /// Zlib Memory Packing failure error.
+ ///
+ [Serializable]
+ public sealed class NotPackableException : IOException
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public NotPackableException()
+ : base()
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The error string.
+ public NotPackableException(string s)
+ : base(s)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The error string.
+ /// The Exception that caused this Exception.
+ public NotPackableException(string s, Exception ex)
+ : base(s, ex)
+ {
+ }
+ }
+}
diff --git a/NotUnpackableException.cs b/NotUnpackableException.cs
new file mode 100644
index 0000000..bddf212
--- /dev/null
+++ b/NotUnpackableException.cs
@@ -0,0 +1,45 @@
+// Copyright (c) 2014-2018, Els_kom org.
+// https://github.com/Elskom/
+// All rights reserved.
+// license: MIT, see LICENSE for more details.
+
+namespace Elskom.Generic.Libs
+{
+ using System;
+ using System.IO;
+
+ ///
+ /// Zlib Memory Unpacking failure error.
+ ///
+ [Serializable]
+ public sealed class NotUnpackableException : IOException
+ {
+ ///
+ /// Initializes a new instance of the class with no argrument.
+ ///
+ public NotUnpackableException()
+ : base()
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class with an string argrument.
+ ///
+ /// The error string.
+ public NotUnpackableException(string s)
+ : base(s)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class with an string argrument
+ /// and the exception that cuased this exception.
+ ///
+ /// The error string.
+ /// The Exception that caused this Exception.
+ public NotUnpackableException(string s, Exception ex)
+ : base(s, ex)
+ {
+ }
+ }
+}
diff --git a/StaticTree.cs b/StaticTree.cs
index f8fd764..eaacb84 100755
--- a/StaticTree.cs
+++ b/StaticTree.cs
@@ -3,7 +3,7 @@
// All rights reserved.
// license: see LICENSE for more details.
-namespace Els_kom.Compression.Libs.Zlib
+namespace Elskom.Generic.Libs
{
internal sealed class StaticTree
{
diff --git a/SupportClass.cs b/SupportClass.cs
index 0b75148..3f4d51c 100755
--- a/SupportClass.cs
+++ b/SupportClass.cs
@@ -3,7 +3,7 @@
// All rights reserved.
// license: see LICENSE for more details.
-namespace Els_kom.Compression.Libs.Zlib
+namespace Elskom.Generic.Libs
{
using System.IO;
using System.Text;
diff --git a/Tree.cs b/Tree.cs
index 74253ec..11ff597 100755
--- a/Tree.cs
+++ b/Tree.cs
@@ -3,7 +3,7 @@
// All rights reserved.
// license: see LICENSE for more details.
-namespace Els_kom.Compression.Libs.Zlib
+namespace Elskom.Generic.Libs
{
internal sealed class Tree
{
diff --git a/ZInputStream.cs b/ZInputStream.cs
index dd9ddb4..3332dd4 100755
--- a/ZInputStream.cs
+++ b/ZInputStream.cs
@@ -3,7 +3,7 @@
// All rights reserved.
// license: see LICENSE for more details.
-namespace Els_kom.Compression.Libs.Zlib
+namespace Elskom.Generic.Libs
{
using System.IO;
diff --git a/ZOutputStream.cs b/ZOutputStream.cs
index a2e0f40..01b85bb 100644
--- a/ZOutputStream.cs
+++ b/ZOutputStream.cs
@@ -3,7 +3,7 @@
// All rights reserved.
// license: see LICENSE for more details.
-namespace Els_kom.Compression.Libs.Zlib
+namespace Elskom.Generic.Libs
{
using System;
using System.IO;
diff --git a/ZStream.cs b/ZStream.cs
index 2d69ca3..e3c9e57 100755
--- a/ZStream.cs
+++ b/ZStream.cs
@@ -3,7 +3,7 @@
// All rights reserved.
// license: see LICENSE for more details.
-namespace Els_kom.Compression.Libs.Zlib
+namespace Elskom.Generic.Libs
{
using System;
diff --git a/ZStreamException.cs b/ZStreamException.cs
index e158fcc..dfd583b 100755
--- a/ZStreamException.cs
+++ b/ZStreamException.cs
@@ -3,7 +3,7 @@
// All rights reserved.
// license: see LICENSE for more details.
-namespace Els_kom.Compression.Libs.Zlib
+namespace Elskom.Generic.Libs
{
using System.IO;
diff --git a/ZlibConst.cs b/ZlibConst.cs
index 600acda..898bcf9 100644
--- a/ZlibConst.cs
+++ b/ZlibConst.cs
@@ -3,7 +3,7 @@
// All rights reserved.
// license: see LICENSE for more details.
-namespace Els_kom.Compression.Libs.Zlib
+namespace Elskom.Generic.Libs
{
///
/// Class that holds the contant values to zlib.
diff --git a/zlib.managed.csproj b/zlib.managed.csproj
index 69cc04c..d28ec28 100644
--- a/zlib.managed.csproj
+++ b/zlib.managed.csproj
@@ -1,4 +1,4 @@
-
+
netcoreapp2.0;netcoreapp2.1;netstandard2.0;net40;net45;net451;net452;net46;net461;net462;net47;net471;net472
@@ -13,8 +13,8 @@
https://github.com/Elskom/zlib.managed/blob/master/LICENSE
Copyright (c) 2018
A cleaned up and bug fixed version of zlib.net. This is also planned to be updated frequently if needed too.
- Target .NET Standard and multiple .NET Framework versions.
- 1.0.2
+ Added memory zlib helper class and rename library namespace.
+ 1.1.0
true