Archive Compression
In many situations you have to deal with compressed archives. Good examples are when you want to provide additional assets for your GitHub releases, or when you depend on other project's release assets yourself, and need to extract them before they can be used.
note
Please refer to the SharpZipLib documentation for any questions.
Compressing Archives
You can create a compressed archive from a directory follows:
- ZIP
- GZIP
- BZIP2
Build.cs
PublishDirectory.ZipTo(
ArchiveFile,
filter: x => !x.HasExtension(ExcludedExtensions),
compressionLevel: CompressionLevel.SmallestSize,
fileMode: FileMode.CreateNew);
Build.cs
PublishDirectory.TarGZipTo(
ArchiveFile,
filter: x => !x.HasExtension(ExcludedExtensions),
fileMode: FileMode.CreateNew);
Build.cs
PublishDirectory.TarBZip2To(
ArchiveFile,
filter: x => !x.HasExtension(ExcludedExtensions),
fileMode: FileMode.CreateNew);
tip
If you want to allow your consumers to verify the integrity of your archive files, you can calculate their MD5 checksums and publish them publicly:
var checksum = ArchiveFile.GetFileHash();
Extracting Archives
You can extract an existing archive file to a directory:
- ZIP
- GZIP
- BZIP2
Build.cs
ArchiveFile.UnZipTo(PublishDirectory);
Build.cs
ArchiveFile.UnTarGZip(PublishDirectory);
Build.cs
ArchiveFile.UnTarBZip2(PublishDirectory);