mirror of
https://github.com/SabreTools/SabreTools.IO.git
synced 2026-07-09 02:08:11 +00:00
Minor fixes and tests for MS-ZIP
This commit is contained in:
32
SabreTools.IO.Test/Compression/MSZIPTests.cs
Normal file
32
SabreTools.IO.Test/Compression/MSZIPTests.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO.Compression.MSZIP;
|
||||
using SabreTools.IO.Extensions;
|
||||
using Xunit;
|
||||
|
||||
namespace SabreTools.IO.Test.Compression
|
||||
{
|
||||
public class MSZIPTests
|
||||
{
|
||||
[Fact]
|
||||
public void DecompressorTest()
|
||||
{
|
||||
// Testing Note: This is a fake file that has multiple blocks
|
||||
// sequentially. In real cabinet files, these are embedded in
|
||||
// CFDATA blocks.
|
||||
string path = Path.Combine(Environment.CurrentDirectory, "TestData", "test-archive.msz");
|
||||
byte[] inputBytes = File.ReadAllBytes(path);
|
||||
MemoryStream input = new MemoryStream(inputBytes);
|
||||
MemoryStream output = new MemoryStream();
|
||||
|
||||
var decompressor = Decompressor.Create();
|
||||
input.SeekIfPossible(0x0000);
|
||||
decompressor.CopyTo(input, output);
|
||||
input.SeekIfPossible(0x3969);
|
||||
decompressor.CopyTo(input, output);
|
||||
|
||||
Assert.Equal(38470, output.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
SabreTools.IO.Test/TestData/test-archive.msz
Normal file
BIN
SabreTools.IO.Test/TestData/test-archive.msz
Normal file
Binary file not shown.
@@ -42,6 +42,10 @@ namespace SabreTools.IO.Compression.MSZIP
|
||||
if (!dest.CanWrite)
|
||||
return false;
|
||||
|
||||
// Ignore if the end of the stream is reached
|
||||
if (source.Position >= source.Length)
|
||||
return false;
|
||||
|
||||
// Validate the header
|
||||
var header = new BlockHeader();
|
||||
header.Signature = source.ReadUInt16LittleEndian();
|
||||
@@ -49,7 +53,7 @@ namespace SabreTools.IO.Compression.MSZIP
|
||||
throw new InvalidDataException(nameof(source));
|
||||
|
||||
byte[] buffer = new byte[32 * 1024];
|
||||
var blockStream = new Deflate.DeflateStream(source, Deflate.CompressionMode.Decompress);
|
||||
var blockStream = new Deflate.DeflateStream(source, Deflate.CompressionMode.Decompress, leaveOpen: true);
|
||||
if (_history != null)
|
||||
blockStream.SetDictionary(_history, check: false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user