Creating Other Archive Types Using 7-Zip Command Line In C# & .NET
[C#, .NET, Compression]
Over the past series of posts, we have looked at how to use the 7-Zip command line to create 7z archives.
What you might not know is that the 7-Zip command-line tool natively supports the creation of the following archive types:
It also supports the extraction of a number of formats:
- APM
- AR
- ARJ
- CAB
- CHM
- COMPOUND
- CPIO
- CramFS
- DMG
- Ext
- FAT
- HFS
- HXS
- iHEX
- ISO
- LZH
- LZMA
- MBR
- MsLZ
- Mub
- NSIS
- NTFS
- MBR
- RAR
- RPM
- PPMD
- QCOW2
- SPLIT
- SquashFS
- UDF
- UEFIc
- UEFIs
- VDI
- VHD
- VMDK
- XAR
- Z
All of this can be leveraged in our code by automating the 7-Zip command-line utility.
The general format to create archives would look like this:
var result = await Cli.Wrap(executablePath) // Set the path to the executable
.WithArguments(args => args
.Add("a") //Specify to create an archive
.Add("-t{INSERT FORMAT HERE}") // Specify the target format
.Add(targetArchiveWithFolder) // Target file name
Remember, some formats only support adding a single file - TAR, BZip2, Gzip, xz
The general format to extract archives would look like this:
var result = await Cli.Wrap(executablePath) // Set the path to the executable
.WithArguments(args => args
.Add("x") //Specify to extract an archive
.Add(sourceArchiveFile) // Source archive file
.Add($"-o{INSERT OUTPUT FOLDER HERE}") // The output folder
TLDR
The 7-Zip command line utility can create and extract a number of archive formats.
Happy hacking!