diff --git a/ImageCore.Tests/TestCompressor.cs b/ImageCore.Tests/TestLosslessCompressor.cs
similarity index 73%
rename from ImageCore.Tests/TestCompressor.cs
rename to ImageCore.Tests/TestLosslessCompressor.cs
index defbd9d..edee4be 100644
--- a/ImageCore.Tests/TestCompressor.cs
+++ b/ImageCore.Tests/TestLosslessCompressor.cs
@@ -34,22 +34,19 @@ namespace ImageCore.Tests
}
[Fact]
- public void TestNullCompressor_Compress()
+ public void TestLosslessCompressor_Compress_Stream()
{
- ICompressor compressor = new NullCompressor();
+ ICompressor compressor = new LosslessCompressor();
var sourceFileName = Path.Combine(_testsProjectDirectory, "test_pictures/IMG_0138.HEIC");
var destinationFileName = Path.GetTempFileName();
File.Copy(sourceFileName, destinationFileName, true);
- compressor.Compress(destinationFileName);
- var originalFile = File.Open(sourceFileName, FileMode.Open);
- var compressedFile = File.Open(destinationFileName, FileMode.Open);
+ var destinationFileHandle = File.Open(destinationFileName, FileMode.Open);
+ var lengthBeforeCompression = destinationFileHandle.Length;
- Assert.True(compressedFile.Length == originalFile.Length);
+ compressor.Compress(destinationFileHandle);
- originalFile.Close();
- compressedFile.Close();
- File.Delete(destinationFileName);
+ Assert.True(destinationFileHandle.Length < lengthBeforeCompression);
}
}
}
\ No newline at end of file
diff --git a/ImageCore.Tests/TestNullCompressor.cs b/ImageCore.Tests/TestNullCompressor.cs
new file mode 100644
index 0000000..068ccd9
--- /dev/null
+++ b/ImageCore.Tests/TestNullCompressor.cs
@@ -0,0 +1,37 @@
+using System;
+using System.IO;
+using Image.Core;
+using Xunit;
+
+namespace ImageCore.Tests
+{
+ public class TestNullCompressor
+ {
+ private readonly string _testsProjectDirectory;
+
+ public TestNullCompressor()
+ {
+ _testsProjectDirectory = Environment.GetEnvironmentVariable("IMAGE_CORE_TESTS");
+ }
+
+
+ [Fact]
+ public void TestNullCompressor_Compress()
+ {
+ ICompressor compressor = new NullCompressor();
+ var sourceFileName = Path.Combine(_testsProjectDirectory, "test_pictures/IMG_0138.HEIC");
+ var destinationFileName = Path.GetTempFileName();
+ File.Copy(sourceFileName, destinationFileName, true);
+ compressor.Compress(destinationFileName);
+
+ var originalFile = File.Open(sourceFileName, FileMode.Open);
+ var compressedFile = File.Open(destinationFileName, FileMode.Open);
+
+ Assert.True(compressedFile.Length == originalFile.Length);
+
+ originalFile.Close();
+ compressedFile.Close();
+ File.Delete(destinationFileName);
+ }
+ }
+}
\ No newline at end of file
diff --git a/ImageCore/Core/ICompressor.cs b/ImageCore/Core/ICompressor.cs
index 1d6835f..d60784b 100644
--- a/ImageCore/Core/ICompressor.cs
+++ b/ImageCore/Core/ICompressor.cs
@@ -1,4 +1,6 @@
-namespace Image.Core
+using System.IO;
+
+namespace Image.Core
{
///
/// ICompressor is an interface for implementing image compressors.
@@ -10,5 +12,11 @@
///
/// The file name of the image to be compressed.
void Compress(string fileName);
+
+ ///
+ /// The method compresses an image in place.
+ ///
+ /// The stream of the image to be compressed.
+ void Compress(Stream stream);
}
}
\ No newline at end of file
diff --git a/ImageCore/Core/LosslessCompressor.cs b/ImageCore/Core/LosslessCompressor.cs
index b8bb397..c3447da 100644
--- a/ImageCore/Core/LosslessCompressor.cs
+++ b/ImageCore/Core/LosslessCompressor.cs
@@ -1,4 +1,5 @@
-using ImageMagick;
+using System.IO;
+using ImageMagick;
namespace Image.Core
{
@@ -22,5 +23,13 @@ namespace Image.Core
{
_imageOptimizer.LosslessCompress(fileName);
}
+
+ ///
+ ///
+ ///
+ public void Compress(Stream stream)
+ {
+ _imageOptimizer.LosslessCompress(stream);
+ }
}
}
\ No newline at end of file
diff --git a/ImageCore/Core/NullCompressor.cs b/ImageCore/Core/NullCompressor.cs
index 9d7545b..db5c99b 100644
--- a/ImageCore/Core/NullCompressor.cs
+++ b/ImageCore/Core/NullCompressor.cs
@@ -1,4 +1,6 @@
-namespace Image.Core
+using System.IO;
+
+namespace Image.Core
{
///
/// Does nothing. Using this Compressor will have no effect.
@@ -13,5 +15,9 @@
public void Compress(string fileName)
{
}
+
+ public void Compress(Stream stream)
+ {
+ }
}
}
\ No newline at end of file
diff --git a/ImgMetadataRemover.sln.DotSettings.user b/ImgMetadataRemover.sln.DotSettings.user
index 536e2d0..c01761f 100644
--- a/ImgMetadataRemover.sln.DotSettings.user
+++ b/ImgMetadataRemover.sln.DotSettings.user
@@ -6,5 +6,10 @@
</AssemblyExplorer>
<SessionState ContinuousTestingMode="0" IsActive="True" Name="TestGetFilenamesFromPath" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
- <Project Location="C:\Users\nutiu\RiderProjects\ImgMetadataRemover\ImageCore.Tests" Presentation="<ImageCore.Tests>" />
+ <Or>
+ <Project Location="C:\Users\nutiu\RiderProjects\ImgMetadataRemover\ImageCore.Tests" Presentation="<ImageCore.Tests>" />
+ <TestAncestor>
+ <TestId>xUnit::B915AC83-B6E9-4E0A-BA88-915F629F57C8::net6.0::ConsoleInterface.Tests.TestSimpleOutputSink</TestId>
+ </TestAncestor>
+ </Or>
</SessionState>
\ No newline at end of file