diff --git a/Examples/App.config b/Examples/App.config
index 343984d..b0827b2 100644
--- a/Examples/App.config
+++ b/Examples/App.config
@@ -2,5 +2,5 @@
-
+
diff --git a/Examples/Examples.csproj b/Examples/Examples.csproj
index 35d2ee4..fc215be 100644
--- a/Examples/Examples.csproj
+++ b/Examples/Examples.csproj
@@ -9,9 +9,9 @@
Properties
Examples
Examples
- v3.5
+ v4.0
512
-
+ Client
false
diff --git a/XZ.NET.Tests/Properties/AssemblyInfo.cs b/XZ.NET.Tests/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..eadb357
--- /dev/null
+++ b/XZ.NET.Tests/Properties/AssemblyInfo.cs
@@ -0,0 +1,20 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+[assembly: AssemblyTitle("XZ.Net.Tests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("XZ.Net.Tests")]
+[assembly: AssemblyCopyright("Copyright © 2018")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+[assembly: ComVisible(false)]
+
+[assembly: Guid("d5018c9d-9a97-4655-bd12-6efc92db0217")]
+
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/XZ.NET.Tests/Samples/A.pdf b/XZ.NET.Tests/Samples/A.pdf
new file mode 100644
index 0000000..1ae192e
Binary files /dev/null and b/XZ.NET.Tests/Samples/A.pdf differ
diff --git a/XZ.NET.Tests/Samples/A.xz b/XZ.NET.Tests/Samples/A.xz
new file mode 100644
index 0000000..721197a
Binary files /dev/null and b/XZ.NET.Tests/Samples/A.xz differ
diff --git a/XZ.NET.Tests/Samples/B.txt b/XZ.NET.Tests/Samples/B.txt
new file mode 100644
index 0000000..e2dcaf8
Binary files /dev/null and b/XZ.NET.Tests/Samples/B.txt differ
diff --git a/XZ.NET.Tests/Samples/B1.xz b/XZ.NET.Tests/Samples/B1.xz
new file mode 100644
index 0000000..8577347
Binary files /dev/null and b/XZ.NET.Tests/Samples/B1.xz differ
diff --git a/XZ.NET.Tests/Samples/B9.xz b/XZ.NET.Tests/Samples/B9.xz
new file mode 100644
index 0000000..3f5c4cf
Binary files /dev/null and b/XZ.NET.Tests/Samples/B9.xz differ
diff --git a/XZ.NET.Tests/Samples/C.bin b/XZ.NET.Tests/Samples/C.bin
new file mode 100644
index 0000000..9111b4c
Binary files /dev/null and b/XZ.NET.Tests/Samples/C.bin differ
diff --git a/XZ.NET.Tests/Samples/C.xz b/XZ.NET.Tests/Samples/C.xz
new file mode 100644
index 0000000..5f24c92
Binary files /dev/null and b/XZ.NET.Tests/Samples/C.xz differ
diff --git a/XZ.NET.Tests/Samples/xz.exe b/XZ.NET.Tests/Samples/xz.exe
new file mode 100644
index 0000000..73ab3bf
Binary files /dev/null and b/XZ.NET.Tests/Samples/xz.exe differ
diff --git a/XZ.NET.Tests/TestSetup.cs b/XZ.NET.Tests/TestSetup.cs
new file mode 100644
index 0000000..ea909c6
--- /dev/null
+++ b/XZ.NET.Tests/TestSetup.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace XZ.NET.Tests
+{
+ [TestClass]
+ public class TestSetup
+ {
+ public static string BaseDir;
+ public static string SampleDir;
+
+ [AssemblyInitialize]
+ public static void Init(TestContext context)
+ {
+ BaseDir = Path.GetFullPath(Path.Combine(TestHelper.GetProgramAbsolutePath(), "..", ".."));
+ SampleDir = Path.Combine(BaseDir, "Samples");
+ }
+
+ [AssemblyCleanup]
+ public static void Cleanup()
+ {
+ }
+ }
+
+ public class TestHelper
+ {
+ public static string GetProgramAbsolutePath()
+ {
+ string path = AppDomain.CurrentDomain.BaseDirectory;
+ if (Path.GetDirectoryName(path) != null)
+ path = path.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
+ return path;
+ }
+ }
+}
diff --git a/XZ.NET.Tests/XZ.NET.Tests.csproj b/XZ.NET.Tests/XZ.NET.Tests.csproj
new file mode 100644
index 0000000..896ec52
--- /dev/null
+++ b/XZ.NET.Tests/XZ.NET.Tests.csproj
@@ -0,0 +1,75 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {D5018C9D-9A97-4655-BD12-6EFC92DB0217}
+ Library
+ Properties
+ XZ.NET.Tests
+ XZ.NET.Tests
+ v4.5
+ 512
+ {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
+ 15.0
+ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
+ $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
+ False
+ UnitTest
+
+
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ ..\XZ.NET\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll
+
+
+ ..\XZ.NET\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {2A389B68-70DC-4853-81AE-56484F32E94D}
+ XZ.NET
+
+
+
+
+
+
+ 이 프로젝트는 이 컴퓨터에 없는 NuGet 패키지를 참조합니다. 해당 패키지를 다운로드하려면 NuGet 패키지 복원을 사용하십시오. 자세한 내용은 http://go.microsoft.com/fwlink/?LinkID=322105를 참조하십시오. 누락된 파일은 {0}입니다.
+
+
+
+
+
+
\ No newline at end of file
diff --git a/XZ.NET.Tests/XZInputStream.Tests.cs b/XZ.NET.Tests/XZInputStream.Tests.cs
new file mode 100644
index 0000000..fa21464
--- /dev/null
+++ b/XZ.NET.Tests/XZInputStream.Tests.cs
@@ -0,0 +1,52 @@
+using System;
+using System.IO;
+using System.Linq;
+using System.Security.Cryptography;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using XZ.NET;
+
+namespace XZ.NET.Tests
+{
+ [TestClass]
+ public class XZInputStreamTests
+ {
+ [TestMethod]
+ [TestCategory("XZ.NET")]
+ public void Decompress()
+ {
+ Decompress_Template("A.xz", "A.pdf");
+ Decompress_Template("B9.xz", "B.txt");
+ Decompress_Template("B1.xz", "B.txt");
+ Decompress_Template("C.xz", "C.bin");
+ }
+
+ public void Decompress_Template(string xzFileName, string originFileName)
+ {
+ byte[] decompDigest;
+ byte[] originDigest;
+
+ string xzFile = Path.Combine(TestSetup.SampleDir, xzFileName);
+ string originFile = Path.Combine(TestSetup.SampleDir, originFileName);
+ using (MemoryStream decompMs = new MemoryStream())
+ {
+ using (FileStream compFs = new FileStream(xzFile, FileMode.Open, FileAccess.Read, FileShare.Read))
+ using (XZInputStream xz = new XZInputStream(compFs))
+ {
+ xz.CopyTo(decompMs);
+ }
+ decompMs.Position = 0;
+
+ HashAlgorithm hash = SHA256.Create();
+ decompDigest = hash.ComputeHash(decompMs);
+ }
+
+ using (FileStream originFs = new FileStream(originFile, FileMode.Open, FileAccess.Read, FileShare.Read))
+ {
+ HashAlgorithm hash = SHA256.Create();
+ originDigest = hash.ComputeHash(originFs);
+ }
+
+ Assert.IsTrue(decompDigest.SequenceEqual(originDigest));
+ }
+ }
+}
diff --git a/XZ.NET.Tests/XZOutputStream.Tests.cs b/XZ.NET.Tests/XZOutputStream.Tests.cs
new file mode 100644
index 0000000..1e1cde3
--- /dev/null
+++ b/XZ.NET.Tests/XZOutputStream.Tests.cs
@@ -0,0 +1,86 @@
+using System;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Security.Cryptography;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using XZ.NET;
+
+namespace XZ.NET.Tests
+{
+ [TestClass]
+ public class XZOutputStreamTests
+ {
+ [TestMethod]
+ [TestCategory("XZ.NET")]
+ public void Compress()
+ {
+ Compress_Template("A.pdf", 1, 9);
+ Compress_Template("B.txt", 1, XZOutputStream.DefaultPreset);
+ Compress_Template("C.bin", 1, 1);
+ }
+
+ [TestMethod]
+ [TestCategory("XZ.NET")]
+ public void CompressMultithread()
+ {
+ Compress_Template("A.pdf", 2, 6);
+ Compress_Template("B.txt", 2, 4);
+ Compress_Template("C.bin", Environment.ProcessorCount, 1);
+ }
+
+ public void Compress_Template(string sampleFileName, int threads, uint preset)
+ {
+ string tempDecompFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
+ string tempXzFile = tempDecompFile + ".xz";
+ try
+ {
+ string sampleFile = Path.Combine(TestSetup.SampleDir, sampleFileName);
+ using (FileStream xzCompFs = new FileStream(tempXzFile, FileMode.Create, FileAccess.Write, FileShare.None))
+ using (FileStream sampleFs = new FileStream(sampleFile, FileMode.Open, FileAccess.Read, FileShare.Read))
+ using (XZOutputStream xz = new XZOutputStream(xzCompFs, threads, preset, true))
+ {
+ sampleFs.CopyTo(xz);
+ }
+
+ Process proc = new Process
+ {
+ StartInfo = new ProcessStartInfo
+ {
+ UseShellExecute = false,
+ CreateNoWindow = true,
+ FileName = Path.Combine(TestSetup.SampleDir, "xz.exe"),
+ Arguments = $"-k -d {tempXzFile}",
+ }
+ };
+ proc.Start();
+ proc.WaitForExit();
+ Assert.IsTrue(proc.ExitCode == 0);
+
+ byte[] decompDigest;
+ byte[] originDigest;
+ using (FileStream fs = new FileStream(sampleFile, FileMode.Open, FileAccess.Read, FileShare.Read))
+ {
+ HashAlgorithm hash = SHA256.Create();
+ originDigest = hash.ComputeHash(fs);
+ }
+
+ using (FileStream fs = new FileStream(tempDecompFile, FileMode.Open, FileAccess.Read, FileShare.Read))
+ {
+ HashAlgorithm hash = SHA256.Create();
+ decompDigest = hash.ComputeHash(fs);
+ }
+
+ Assert.IsTrue(originDigest.SequenceEqual(decompDigest));
+
+ }
+ finally
+ {
+ if (File.Exists(tempXzFile))
+ File.Delete(tempXzFile);
+ if (File.Exists(tempDecompFile))
+ File.Delete(tempDecompFile);
+ }
+ }
+ }
+}
diff --git a/XZ.NET.Tests/packages.config b/XZ.NET.Tests/packages.config
new file mode 100644
index 0000000..03805ce
--- /dev/null
+++ b/XZ.NET.Tests/packages.config
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/XZ.NET/XZ.NET.csproj b/XZ.NET/XZ.NET.csproj
index 4709d50..f9c0a0f 100644
--- a/XZ.NET/XZ.NET.csproj
+++ b/XZ.NET/XZ.NET.csproj
@@ -9,9 +9,9 @@
Properties
XZ.NET
XZ.NET
- v2.0
+ v4.0
512
-
+ Client
true
@@ -22,6 +22,7 @@
DEBUG;TRACE
prompt
4
+ false
pdbonly
@@ -30,6 +31,7 @@
TRACE
prompt
4
+ false
diff --git a/XZ.NET/XZ.NET.sln b/XZ.NET/XZ.NET.sln
index cde9240..2118f06 100644
--- a/XZ.NET/XZ.NET.sln
+++ b/XZ.NET/XZ.NET.sln
@@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XZ.NET", "XZ.NET.csproj", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Examples", "..\Examples\Examples.csproj", "{EBEC5795-82AB-455E-806B-64099BA50A0A}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XZ.NET.Tests", "..\XZ.NET.Tests\XZ.NET.Tests.csproj", "{D5018C9D-9A97-4655-BD12-6EFC92DB0217}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -21,8 +23,15 @@ Global
{EBEC5795-82AB-455E-806B-64099BA50A0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EBEC5795-82AB-455E-806B-64099BA50A0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EBEC5795-82AB-455E-806B-64099BA50A0A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D5018C9D-9A97-4655-BD12-6EFC92DB0217}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D5018C9D-9A97-4655-BD12-6EFC92DB0217}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D5018C9D-9A97-4655-BD12-6EFC92DB0217}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D5018C9D-9A97-4655-BD12-6EFC92DB0217}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {E8D4071D-94BA-43BD-A629-E87AEFBDA58A}
+ EndGlobalSection
EndGlobal
diff --git a/XZ.NET/XZInputStream.cs b/XZ.NET/XZInputStream.cs
index 3d29e0f..028185b 100644
--- a/XZ.NET/XZInputStream.cs
+++ b/XZ.NET/XZInputStream.cs
@@ -31,7 +31,7 @@ public unsafe class XZInputStream : Stream
{
private LzmaStream _lzmaStream;
private readonly Stream _mInnerStream;
- private readonly bool leaveOpen;
+ private readonly bool _leaveOpen;
private readonly byte[] _inbuf;
private int _inbufOffset;
private long _length;
@@ -44,9 +44,8 @@ public unsafe class XZInputStream : Stream
public XZInputStream(Stream s) : this(s, false) { }
public XZInputStream(Stream s, bool leaveOpen) : this()
{
- if(s == null) throw new ArgumentNullException();
- _mInnerStream = s;
- this.leaveOpen = leaveOpen;
+ _mInnerStream = s ?? throw new ArgumentNullException();
+ _leaveOpen = leaveOpen;
_inbuf = new byte[BufSize];
}
@@ -153,20 +152,11 @@ public override void Write(byte[] buffer, int offset, int count)
throw new NotSupportedException("XZ Input stream does not support writing");
}
- public override bool CanRead
- {
- get { return true; }
- }
+ public override bool CanRead => true;
- public override bool CanSeek
- {
- get { return false; }
- }
+ public override bool CanSeek => false;
- public override bool CanWrite
- {
- get { return false; }
- }
+ public override bool CanWrite => false;
///
/// Gets the size of uncompressed data in bytes
@@ -247,8 +237,8 @@ public static byte[] Decode(byte[] buffer)
public override long Position
{
- get { throw new NotSupportedException("XZ Stream does not support getting position"); }
- set { throw new NotSupportedException("XZ Stream does not support setting position"); }
+ get => throw new NotSupportedException("XZ Stream does not support getting position");
+ set => throw new NotSupportedException("XZ Stream does not support setting position");
}
~XZInputStream() { Dispose(false); }
@@ -257,7 +247,7 @@ protected override void Dispose(bool disposing)
{
Native.lzma_end(ref _lzmaStream);
- if(disposing && !leaveOpen) _mInnerStream?.Close();
+ if(disposing && !_leaveOpen) _mInnerStream?.Close();
base.Dispose(disposing);
}
diff --git a/XZ.NET/XZOutputStream.cs b/XZ.NET/XZOutputStream.cs
index 840ac34..2b6e49a 100644
--- a/XZ.NET/XZOutputStream.cs
+++ b/XZ.NET/XZOutputStream.cs
@@ -32,7 +32,7 @@ public unsafe class XZOutputStream : Stream
{
private LzmaStream _lzmaStream;
private readonly Stream _mInnerStream;
- private readonly bool leaveOpen;
+ private readonly bool _leaveOpen;
private readonly byte[] _outbuf;
///
@@ -51,7 +51,7 @@ public XZOutputStream(Stream s, int threads, uint preset) : this(s, threads, pre
public XZOutputStream(Stream s, int threads, uint preset, bool leaveOpen)
{
_mInnerStream = s;
- this.leaveOpen = leaveOpen;
+ _leaveOpen = leaveOpen;
LzmaReturn ret;
if(threads == 1) ret = Native.lzma_easy_encoder(ref _lzmaStream, preset, LzmaCheck.LzmaCheckCrc64);
@@ -151,30 +151,18 @@ static Exception GetError(LzmaReturn ret)
}
}
- public override bool CanRead
- {
- get { return false; }
- }
+ public override bool CanRead => false;
- public override bool CanSeek
- {
- get { return false; }
- }
+ public override bool CanSeek => false;
- public override bool CanWrite
- {
- get { return true; }
- }
+ public override bool CanWrite => true;
- public override long Length
- {
- get { throw new NotSupportedException(); }
- }
+ public override long Length => throw new NotSupportedException();
public override long Position
{
- get { throw new NotSupportedException(); }
- set { throw new NotSupportedException(); }
+ get => throw new NotSupportedException();
+ set => throw new NotSupportedException();
}
public override void Close()
@@ -224,7 +212,7 @@ protected override void Dispose(bool disposing)
{
Native.lzma_end(ref _lzmaStream);
- if(disposing && !leaveOpen) _mInnerStream?.Close();
+ if(disposing && !_leaveOpen) _mInnerStream?.Close();
base.Dispose(disposing);
}
diff --git a/XZ.NET/liblzma.dll b/XZ.NET/liblzma.dll
index aa4ec80..6fe78c8 100644
Binary files a/XZ.NET/liblzma.dll and b/XZ.NET/liblzma.dll differ
diff --git a/XZ.NET/liblzma64.dll b/XZ.NET/liblzma64.dll
index b0d5ce4..2a2e4c7 100644
Binary files a/XZ.NET/liblzma64.dll and b/XZ.NET/liblzma64.dll differ