-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Open
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.IO.Compression
Milestone
Description
Background and motivation
We are using Zip as simple container for a bunch of image files (JPEG). We need to make sure that function only process STORE ZipArchiveEntry (aka NoCompression). Right now we compare entry.CompressedLength against entry.Length to deduce if the entry is really STORE (and not DEFLATE).
It would make sense to expose directly CompressionMethod as read-only for simplicity.
API Proposal (updated by @iremyux)
public class ZipArchiveEntry
{
+ public ZipCompressionMethod CompressionMethod { get; }
}
// Corresponds to the Compression Method described by APPNOTE.TXT section 4.4.5
+public enum ZipCompressionMethod : ushort
+{
+ Stored = 0x0,
+ Deflate = 0x8,
+ Deflate64 = 0x9,
+ BZip2 = 0xC,
+ Lzma = 0xE
+}API Usage
using var archive = ZipFile.Open(zipFileName, ZipArchiveMode.Read);
foreach (var entry in archive.Entries)
{
if (entry.CompressionMethod != CompressionMethodValues.Stored )
throw new NotImplementedException("Only process STORE type")
}Alternative Designs (updated by @iremyux)
using var archive = ZipFile.Open(zipFileName, ZipArchiveMode.Read);
foreach (var entry in archive.Entries)
{
if (entry.CompressedLength != entry.Length)
throw new NotImplementedException("Only process STORE type")
}public class ZipArchiveEntry
{
public CompressionMethod CompressionMethod { get; }
}We discussed naming the enum CompressionMethod & if it can be used by other formats as well. But currently we do not see any need for it. Also the codebase already uses domain-specific prefixes.
public enum CompressionMethod : ushort
{
Stored = 0x0,
Deflate = 0x1,
Deflate64 = 0x2,
BZip2 = 0x3,
Lzma = 0x4
}We have to do the matching again since the ZIP headers will contain the specifications' values.
Risks
No response
MichalPetryka
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.IO.Compression