Minor fixes and tests for MS-ZIP

This commit is contained in:
Matt Nadareski
2025-07-23 14:45:33 -04:00
parent 16248ef02f
commit cf4f613a65
3 changed files with 37 additions and 1 deletions

View 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);
}
}
}

Binary file not shown.

View File

@@ -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);