This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commit a76327a
1 parent 2fb4a0b commit a76327a Copy full SHA for a76327a
File tree 2 files changed +41
-8
lines changed
src/ICSharpCode.SharpZipLib/Zip
2 files changed +41
-8
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Text ;
4
+
5
+ namespace ICSharpCode . SharpZipLib . Zip
6
+ {
7
+ /// <summary>
8
+ /// General ZipEntry helper extensions
9
+ /// </summary>
10
+ public static class ZipEntryExtensions
11
+ {
12
+ /// <summary>
13
+ /// Efficiently check if a <see cref="GeneralBitFlags">flag</see> is set without enum un-/boxing
14
+ /// </summary>
15
+ /// <param name="entry"></param>
16
+ /// <param name="flag"></param>
17
+ /// <returns>Returns whether the flag was set</returns>
18
+ public static bool HasFlag ( this ZipEntry entry , GeneralBitFlags flag )
19
+ => ( entry . Flags & ( int ) flag ) != 0 ;
20
+
21
+ /// <summary>
22
+ /// Efficiently set a <see cref="GeneralBitFlags">flag</see> without enum un-/boxing
23
+ /// </summary>
24
+ /// <param name="entry"></param>
25
+ /// <param name="flag"></param>
26
+ /// <param name="enabled">Whether the passed flag should be set (1) or cleared (0)</param>
27
+ public static void SetFlag ( this ZipEntry entry , GeneralBitFlags flag , bool enabled = true )
28
+ => entry . Flags = enabled
29
+ ? entry . Flags | ( int ) flag
30
+ : entry . Flags & ~ ( int ) flag ;
31
+ }
32
+ }
Original file line number Diff line number Diff line change @@ -126,14 +126,15 @@ public string Password
126
126
/// <remarks>
127
127
/// The entry can only be decompressed if the library supports the zip features required to extract it.
128
128
/// See the <see cref="ZipEntry.Version">ZipEntry Version</see> property for more details.
129
+ ///
130
+ /// Since <see cref="ZipInputStream"/> uses the local headers for extraction, entries with no compression combined with the
131
+ /// <see cref="GeneralBitFlags.Descriptor"/> flag set, cannot be extracted as the end of the entry data cannot be deduced.
129
132
/// </remarks>
130
- public bool CanDecompressEntry
131
- {
132
- get
133
- {
134
- return ( entry != null ) && IsEntryCompressionMethodSupported ( entry ) && entry . CanDecompress ;
135
- }
136
- }
133
+ public bool CanDecompressEntry
134
+ => entry != null
135
+ && IsEntryCompressionMethodSupported ( entry )
136
+ && entry . CanDecompress
137
+ && ( ! entry . HasFlag ( GeneralBitFlags . Descriptor ) || entry . CompressionMethod != CompressionMethod . Stored ) ;
137
138
138
139
/// <summary>
139
140
/// Is the compression method for the specified entry supported?
@@ -142,7 +143,7 @@ public bool CanDecompressEntry
142
143
/// Uses entry.CompressionMethodForHeader so that entries of type WinZipAES will be rejected.
143
144
/// </remarks>
144
145
/// <param name="entry">the entry to check.</param>
145
- /// <returns>true if the compression methiod is supported, false if not.</returns>
146
+ /// <returns>true if the compression method is supported, false if not.</returns>
146
147
private static bool IsEntryCompressionMethodSupported ( ZipEntry entry )
147
148
{
148
149
var entryCompressionMethod = entry . CompressionMethodForHeader ;
You can’t perform that action at this time.
0 commit comments