Skip to content

Commit 9f563dd

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

6 files changed

Lines changed: 73 additions & 1 deletion

File tree

‎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+
<NoneInclude="packaged_resources">
33+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
34+
</None>
3235
</ItemGroup>
3336

3437
<TargetName="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+
publicvoidUpdateEntryCompressionMethod()
197+
{
198+
varzipStream=newMemoryStream();
199+
varencoding=Encoding.UTF8;
200+
using(varzip=ZipArchive.Create(zipStream)){
201+
zip.AddEntry("foo","bar",encoding,CompressionMethod.Deflate);
202+
}
203+
using(varzip=ZipArchive.Open(zipStream)){
204+
varentry=zip.ReadEntry("foo");
205+
Assert.IsNotNull(entry,"Entry 'foo' should exist!");
206+
AssertEntryIsValid(entry,"foo",compression:CompressionMethod.Deflate);
207+
using(varstream=newMemoryStream()){
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+
publicvoidCheckForUnknownCompressionMethods()
220+
{
221+
stringfilePath=Path.GetFullPath("packaged_resources");
222+
if(!File.Exists(filePath)){
223+
filePath=Path.GetFullPath(Path.Combine("LibZipSharp.UnitTest","packaged_resources"));
224+
}
225+
using(varzip=ZipArchive.Open(filePath,FileMode.Open)){
226+
foreach(vareinzip){
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
publicvoidEnumerateSkipDeletedEntries(booldeleteFromExistingFile)
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
<ProjectDefaultTargets="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
publicintwhence;
4848
};
4949

50+
[StructLayout(LayoutKind.Explicit)]
5051
publicstructzip_stat_t
5152
{
53+
[FieldOffset(0)]
5254
publicUInt64valid;/* which fields have valid values */
55+
[FieldOffset(8)]
5356
publicIntPtrname;/* name of the file (char *) */
57+
[FieldOffset(16)]
5458
publicUInt64index;/* index within archive */
59+
[FieldOffset(24)]
5560
publicUInt64size;/* size of file (uncompressed) */
61+
[FieldOffset(32)]
5662
publicUInt64comp_size;/* size of file (compressed) */
63+
[FieldOffset(40)]
5764
publicIntPtrmtime;/* modification time (time_t) */
65+
[FieldOffset(48)]
5866
publicUInt32crc;/* crc of file data */
67+
[FieldOffset(52)]
5968
publicInt16comp_method;/* compression method used */
69+
[FieldOffset(56)]
6070
publicUInt16encryption_method;/* encryption method used */
71+
[FieldOffset(60)]
6172
publicUInt32flags;/* reserved for future use */
6273
};
6374

0 commit comments

Comments
 (0)