Implement IDisposable on IDeflateStream
Merge pull request #36 from airzy91/feature/IDisposeableOnIDeflateStream
This commit is contained in:
Коммит
39569beaf0
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.IO.Compression;
|
||||
|
||||
namespace SystemInterface.IO.Compression
|
||||
|
@ -5,7 +6,7 @@ namespace SystemInterface.IO.Compression
|
|||
/// <summary>
|
||||
/// Description of IDeflateStreamWrap.
|
||||
/// </summary>
|
||||
public interface IDeflateStream
|
||||
public interface IDeflateStream : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the DeflateStream class using the specified stream and CompressionMode value, and a value that specifies whether to leave the stream open.
|
||||
|
@ -19,6 +20,16 @@ namespace SystemInterface.IO.Compression
|
|||
/// </summary>
|
||||
void Close();
|
||||
|
||||
/// <summary>
|
||||
/// Reads the bytes from the current stream and writes them to another stream.
|
||||
/// </summary>
|
||||
/// <param name="destination"></param>
|
||||
/// <exception cref="System.ArgumentNullException">destination is null.</exception>
|
||||
/// <exception cref="System.NotSupportedException">The current stream does not support reading,-or- the destination stream does not support writing.</exception>
|
||||
/// <exception cref="System.ObjectDisposedException">Either the current stream or the destination were closed before the CopyTo(stream) method was called.</exception>
|
||||
/// <exception cref="System.IO.IOException">An I/O exception occurred.</exception>
|
||||
void CopyTo(IStream destination);
|
||||
|
||||
/// <summary>
|
||||
/// Flushes the contents of the internal buffer of the current stream object to the underlying stream.
|
||||
/// </summary>
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
using System.IO;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Net.Mime;
|
||||
using System.Text;
|
||||
using SystemWrapper.IO;
|
||||
using SystemWrapper.IO.Compression;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using System.Windows.Forms;
|
||||
using SystemInterface.IO;
|
||||
|
||||
namespace SystemWrapper.Tests.IO
|
||||
|
@ -51,6 +50,37 @@ namespace SystemWrapper.Tests.IO
|
|||
Assert.IsNotNull(instance.DeflateStreamInstance);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Integration_Test()
|
||||
{
|
||||
var textToCompress = "Hello World";
|
||||
var originalBytes = Encoding.UTF8.GetBytes(textToCompress);
|
||||
byte[] compressedBytes;
|
||||
byte[] decompressedBytes;
|
||||
|
||||
using (var memoryStream = new MemoryStreamWrap())
|
||||
{
|
||||
var compressInstance = new DeflateStreamWrap(memoryStream, CompressionMode.Compress);
|
||||
compressInstance.Write(originalBytes, 0, originalBytes.Length);
|
||||
compressInstance.Dispose();
|
||||
|
||||
compressedBytes = memoryStream.ToArray();
|
||||
}
|
||||
|
||||
using (var compressedMemoryStream = new MemoryStreamWrap(compressedBytes))
|
||||
{
|
||||
using (var deflateStream = new DeflateStreamWrap(compressedMemoryStream, CompressionMode.Decompress))
|
||||
{
|
||||
using (var resultStream = new MemoryStreamWrap())
|
||||
{
|
||||
deflateStream.CopyTo(resultStream);
|
||||
decompressedBytes = resultStream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Assert.AreEqual(textToCompress, Encoding.UTF8.GetString(decompressedBytes));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
using System.IO.Compression;
|
||||
using System.IO.Compression;
|
||||
using SystemInterface.IO;
|
||||
using SystemInterface.IO.Compression;
|
||||
|
||||
|
@ -41,6 +41,9 @@ namespace SystemWrapper.IO.Compression
|
|||
|
||||
#endregion Constructors and Initializers
|
||||
|
||||
/// <inheritdoc />
|
||||
public DeflateStream DeflateStreamInstance { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Read(byte[] array, int offset, int count)
|
||||
{
|
||||
|
@ -53,6 +56,11 @@ namespace SystemWrapper.IO.Compression
|
|||
DeflateStreamInstance.Write(array, offset, count);
|
||||
}
|
||||
|
||||
public void CopyTo(IStream destination)
|
||||
{
|
||||
DeflateStreamInstance.CopyTo(destination.StreamInstance);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Flush()
|
||||
{
|
||||
|
@ -66,6 +74,9 @@ namespace SystemWrapper.IO.Compression
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public DeflateStream DeflateStreamInstance { get; private set; }
|
||||
public void Dispose()
|
||||
{
|
||||
DeflateStreamInstance.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче