Skip to content

Add a test which changes the CompressionMethod of an item #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CompressionMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,26 @@ public enum CompressionMethod : short
/// </summary>
LZ77 = 19,

/// <summary>
/// LZMA2 Compressed data
/// </summary>
LZMA2 = 33,

/// <summary>
/// Zstandard compressed data
/// </summary>
ZSTD = 93,

/// <summary>
/// XZ compressed data
/// </summary>
XZ = 95,

/// <summary>
/// Compressed Jpeg data
/// </summary>
JPEG = 96,

/// <summary>
/// WavPack compressed data
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<Link>libzip.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packaged_resources">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<Target Name="RunNunitTests" DependsOnTargets="Build">
Expand Down
38 changes: 38 additions & 0 deletions LibZipSharp.UnitTest/ZipTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,44 @@ public void SmallTextFile ()
}
}

[Test]
public void UpdateEntryCompressionMethod ()
{
var zipStream = new MemoryStream ();
var encoding = Encoding.UTF8;
using (var zip = ZipArchive.Create (zipStream)) {
zip.AddEntry ("foo", "bar", encoding, CompressionMethod.Deflate);
}
using (var zip = ZipArchive.Open (zipStream)) {
var entry = zip.ReadEntry ("foo");
Assert.IsNotNull (entry, "Entry 'foo' should exist!");
AssertEntryIsValid (entry, "foo", compression: CompressionMethod.Deflate);
using (var stream = new MemoryStream ()) {
entry.Extract (stream);
stream.Position = 0;
Assert.AreEqual ("bar", encoding.GetString (stream.ToArray ()));
}
zip.AddEntry ("foo", "foo", encoding, CompressionMethod.Store);
entry = zip.ReadEntry ("foo");
AssertEntryIsValid (entry, "foo", compression: CompressionMethod.Store);
}
}

[Test]
public void CheckForUnknownCompressionMethods ()
{
string filePath = Path.GetFullPath ("packaged_resources");
if (!File.Exists (filePath)) {
filePath = Path.GetFullPath (Path.Combine ("LibZipSharp.UnitTest", "packaged_resources"));
}
using (var zip = ZipArchive.Open (filePath, FileMode.Open)) {
foreach (var e in zip) {
Console.WriteLine ($"{e.FullName} is {e.CompressionMethod}");
Assert.AreNotEqual (CompressionMethod.Unknown, e.CompressionMethod, "Compression Method should not be Unknown.");
}
}
}

[TestCase (false)]
[TestCase (true)]
public void EnumerateSkipDeletedEntries (bool deleteFromExistingFile)
Expand Down
Binary file added LibZipSharp.UnitTest/packaged_resources
Binary file not shown.
2 changes: 1 addition & 1 deletion LibZipSharp.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LibZipSharpNugetVersion>1.0.21</_LibZipSharpNugetVersion>
<_LibZipSharpNugetVersion>1.0.22</_LibZipSharpNugetVersion>
</PropertyGroup>
</Project>
11 changes: 11 additions & 0 deletions Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,28 @@ public struct zip_source_args_seek_t
public int whence;
};

[StructLayout(LayoutKind.Explicit)]
public struct zip_stat_t
{
[FieldOffset (0)]
public UInt64 valid; /* which fields have valid values */
[FieldOffset (8)]
public IntPtr name; /* name of the file (char *) */
[FieldOffset (16)]
public UInt64 index; /* index within archive */
[FieldOffset (24)]
public UInt64 size; /* size of file (uncompressed) */
[FieldOffset (32)]
public UInt64 comp_size; /* size of file (compressed) */
[FieldOffset (40)]
public IntPtr mtime; /* modification time (time_t) */
[FieldOffset (48)]
public UInt32 crc; /* crc of file data */
[FieldOffset (52)]
public Int16 comp_method; /* compression method used */
[FieldOffset (56)]
public UInt16 encryption_method; /* encryption method used */
[FieldOffset (60)]
public UInt32 flags; /* reserved for future use */
};

Expand Down