Q: ArchiveType vs CompressionType #251

Closed
opened 2026-01-29 22:09:00 +00:00 by claunia · 7 comments
Owner

Originally created by @evil-shrike on GitHub (Oct 26, 2017).

Hi!

I can't understand how to choose a format. When I create a stream I use ArchiveFactory.Create(ArchiveType.Zip) but then I have to choose CompressionType :

_zipStream = ArchiveFactory.Create(ArchiveType.Zip);
_zipStream.SaveTo(PackageStream, new WriterOptions(CompressionType.GZip));

why? How do ArchiveType and CompressionType relate to each other?

Moreover this code throws SharpCompress.Common.InvalidFormatException: Invalid compression method: GZip.
Zip archive can't have GZip compression type?
I found out that ArchiveType.Zip is compatible with CompressionType.Deflate. But it's weird API.

Originally created by @evil-shrike on GitHub (Oct 26, 2017). Hi! I can't understand how to choose a format. When I create a stream I use `ArchiveFactory.Create(ArchiveType.Zip)` but then I have to choose CompressionType : ``` _zipStream = ArchiveFactory.Create(ArchiveType.Zip); _zipStream.SaveTo(PackageStream, new WriterOptions(CompressionType.GZip)); ``` why? How do ArchiveType and CompressionType relate to each other? Moreover this code throws SharpCompress.Common.InvalidFormatException: Invalid compression method: GZip. Zip archive can't have GZip compression type? I found out that ArchiveType.Zip is compatible with CompressionType.Deflate. But it's weird API.
claunia added the question label 2026-01-29 22:09:00 +00:00
Author
Owner

@adamhathcock commented on GitHub (Oct 26, 2017):

You've got it it seems. Yes, GZip is slightly weird and isn't supported on Zip as detailed here: https://github.com/adamhathcock/sharpcompress/wiki/Supported-Formats

Yes, it is slightly weird because it's trying to be powerful. If you've got suggestions on how to fix the API, then please let me know.

@adamhathcock commented on GitHub (Oct 26, 2017): You've got it it seems. Yes, GZip is slightly weird and isn't supported on Zip as detailed here: https://github.com/adamhathcock/sharpcompress/wiki/Supported-Formats Yes, it is slightly weird because it's trying to be powerful. If you've got suggestions on how to fix the API, then please let me know.
Author
Owner

@evil-shrike commented on GitHub (Oct 26, 2017):

Ok, got it.
ArchiveType determines a subset of compression types.
Well, I'd suggest some default SaveTo:

interface IWritableArchive {
  void SaveTo(Stream stream, WriterOptions options = null);
}

if no WriterOptions was specified then the lib will choose some default based on its ArchiveType.

@evil-shrike commented on GitHub (Oct 26, 2017): Ok, got it. ArchiveType determines a subset of compression types. Well, I'd suggest some default `SaveTo`: ``` interface IWritableArchive { void SaveTo(Stream stream, WriterOptions options = null); } ``` if no `WriterOptions` was specified then the lib will choose some default based on its ArchiveType.
Author
Owner

@adamhathcock commented on GitHub (Oct 26, 2017):

You can also just put CompressionType in directly as it's implicitly converted.

@adamhathcock commented on GitHub (Oct 26, 2017): You can also just put `CompressionType` in directly as it's implicitly converted.
Author
Owner

@evil-shrike commented on GitHub (Oct 26, 2017):

Ok, that's nice.
But I meant to allow skipping CompressionType at all: zipArchive.SaveTo(stream)

@evil-shrike commented on GitHub (Oct 26, 2017): Ok, that's nice. But I meant to allow skipping `CompressionType` at all: `zipArchive.SaveTo(stream)`
Author
Owner

@adamhathcock commented on GitHub (Oct 26, 2017):

Yeah that's fine too.

@adamhathcock commented on GitHub (Oct 26, 2017): Yeah that's fine too.
Author
Owner

@evil-shrike commented on GitHub (Oct 26, 2017):

but it doesn't work ) there's no such method in IWritableArchive

@evil-shrike commented on GitHub (Oct 26, 2017): but it doesn't work ) there's no such method in `IWritableArchive`
Author
Owner
@adamhathcock commented on GitHub (Oct 26, 2017): Looks like this https://github.com/adamhathcock/sharpcompress/blob/master/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs#L269
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#251