Skip to content

Commit

Permalink
Merge pull request #735 from Erior/feature/Expand-Delta-distance-tests
Browse files Browse the repository at this point in the history
Remove check for minimal distance and add test case generated by 7z as compatibility check
  • Loading branch information
adamhathcock committed Mar 21, 2023
2 parents dfa4bb6 + 9544960 commit 0129b31
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
5 changes: 0 additions & 5 deletions src/SharpCompress/Compressors/Filters/DeltaFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ public DeltaFilter(bool isEncoder, Stream baseStream, byte[] info)
_distance = info[0];
_history = new byte[DISTANCE_MAX];
_position = 0;

if (_distance < DISTANCE_MIN)
{
throw new NotSupportedException();
}
}

protected override int Transform(byte[] buffer, int offset, int count)
Expand Down
25 changes: 25 additions & 0 deletions tests/SharpCompress.Test/ArchiveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,29 @@ protected void ArchiveFileReadEx(string testArchive)
}
VerifyFilesEx();
}

protected void ArchiveDeltaDistanceRead(string testArchive)
{
testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive);
using (var archive = Archives.ArchiveFactory.Open(testArchive, null))
using (var reader = archive.ExtractAllEntries())
while (reader.MoveToNextEntry())
{
if (!reader.Entry.IsDirectory)
{
var memory = new MemoryStream();
reader.WriteEntryTo(memory);

memory.Position = 0;

for (int y = 0; y < 9; y++)
for (int x = 0; x < 256; x++)
{
Assert.Equal(x, memory.ReadByte());
}

Assert.Equal((int)-1, memory.ReadByte());
}
}
}
}
6 changes: 5 additions & 1 deletion tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using SharpCompress.Common;
using SharpCompress.Readers;
using Xunit;
Expand Down Expand Up @@ -111,6 +112,9 @@ public class SevenZipArchiveTests : ArchiveTests
//"7Zip.BZip2.split.007"

[Fact]
public void SevenZipArchive_delta_FileRead() =>
public void SevenZipArchive_Delta_FileRead() =>
ArchiveFileRead("7Zip.delta.7z");

[Fact]
public void SevenZipArchive_Delta_Distance() => ArchiveDeltaDistanceRead("7Zip.delta.distance.7z");
}
Binary file not shown.

0 comments on commit 0129b31

Please sign in to comment.