Skip to content

Commit 9f563dd

Browse files
authored
Add a test which changes the CompressionMethod of an item (#78)
1 parent 3b610c9 commit 9f563dd

File tree

6 files changed

+73
-1
lines changed

6 files changed

+73
-1
lines changed

CompressionMethod.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,26 @@ public enum CompressionMethod : short
121121
/// </summary>
122122
LZ77 = 19,
123123

124+
/// <summary>
125+
/// LZMA2 Compressed data
126+
/// </summary>
127+
LZMA2 = 33,
128+
129+
/// <summary>
130+
/// Zstandard compressed data
131+
/// </summary>
132+
ZSTD = 93,
133+
134+
/// <summary>
135+
/// XZ compressed data
136+
/// </summary>
137+
XZ = 95,
138+
139+
/// <summary>
140+
/// Compressed Jpeg data
141+
/// </summary>
142+
JPEG = 96,
143+
124144
/// <summary>
125145
/// WavPack compressed data
126146
/// </summary>

LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
<Link>libzip.dll</Link>
3030
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3131
</None>
32+
<None Include="packaged_resources">
33+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
34+
</None>
3235
</ItemGroup>
3336

3437
<Target Name="RunNunitTests" DependsOnTargets="Build">

LibZipSharp.UnitTest/ZipTests.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,44 @@ public void SmallTextFile ()
192192
}
193193
}
194194

195+
[Test]
196+
public void UpdateEntryCompressionMethod ()
197+
{
198+
var zipStream = new MemoryStream ();
199+
var encoding = Encoding.UTF8;
200+
using (var zip = ZipArchive.Create (zipStream)) {
201+
zip.AddEntry ("foo", "bar", encoding, CompressionMethod.Deflate);
202+
}
203+
using (var zip = ZipArchive.Open (zipStream)) {
204+
var entry = zip.ReadEntry ("foo");
205+
Assert.IsNotNull (entry, "Entry 'foo' should exist!");
206+
AssertEntryIsValid (entry, "foo", compression: CompressionMethod.Deflate);
207+
using (var stream = new MemoryStream ()) {
208+
entry.Extract (stream);
209+
stream.Position = 0;
210+
Assert.AreEqual ("bar", encoding.GetString (stream.ToArray ()));
211+
}
212+
zip.AddEntry ("foo", "foo", encoding, CompressionMethod.Store);
213+
entry = zip.ReadEntry ("foo");
214+
AssertEntryIsValid (entry, "foo", compression: CompressionMethod.Store);
215+
}
216+
}
217+
218+
[Test]
219+
public void CheckForUnknownCompressionMethods ()
220+
{
221+
string filePath = Path.GetFullPath ("packaged_resources");
222+
if (!File.Exists (filePath)) {
223+
filePath = Path.GetFullPath (Path.Combine ("LibZipSharp.UnitTest", "packaged_resources"));
224+
}
225+
using (var zip = ZipArchive.Open (filePath, FileMode.Open)) {
226+
foreach (var e in zip) {
227+
Console.WriteLine ($"{e.FullName} is {e.CompressionMethod}");
228+
Assert.AreNotEqual (CompressionMethod.Unknown, e.CompressionMethod, "Compression Method should not be Unknown.");
229+
}
230+
}
231+
}
232+
195233
[TestCase (false)]
196234
[TestCase (true)]
197235
public void EnumerateSkipDeletedEntries (bool deleteFromExistingFile)
51.6 KB
Binary file not shown.

LibZipSharp.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22
<PropertyGroup>
3-
<_LibZipSharpNugetVersion>1.0.21</_LibZipSharpNugetVersion>
3+
<_LibZipSharpNugetVersion>1.0.22</_LibZipSharpNugetVersion>
44
</PropertyGroup>
55
</Project>

Native.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,28 @@ public struct zip_source_args_seek_t
4747
public int whence;
4848
};
4949

50+
[StructLayout(LayoutKind.Explicit)]
5051
public struct zip_stat_t
5152
{
53+
[FieldOffset (0)]
5254
public UInt64 valid; /* which fields have valid values */
55+
[FieldOffset (8)]
5356
public IntPtr name; /* name of the file (char *) */
57+
[FieldOffset (16)]
5458
public UInt64 index; /* index within archive */
59+
[FieldOffset (24)]
5560
public UInt64 size; /* size of file (uncompressed) */
61+
[FieldOffset (32)]
5662
public UInt64 comp_size; /* size of file (compressed) */
63+
[FieldOffset (40)]
5764
public IntPtr mtime; /* modification time (time_t) */
65+
[FieldOffset (48)]
5866
public UInt32 crc; /* crc of file data */
67+
[FieldOffset (52)]
5968
public Int16 comp_method; /* compression method used */
69+
[FieldOffset (56)]
6070
public UInt16 encryption_method; /* encryption method used */
71+
[FieldOffset (60)]
6172
public UInt32 flags; /* reserved for future use */
6273
};
6374

0 commit comments

Comments
 (0)