Collect files to cpio and compress
Contents
[
Hide
Show
]Cpio purpose
Cpio format is similar to tar. Cpio archive allows you to combine several files into a single file. You may compress the joint file, too.
Collecting without compression
There is a sample of collecting two files into a cpio archive.
1using (FileStream cpioFile = File.Open("combined.cpio", FileMode.Create))
2{
3 FileInfo fi1 = new FileInfo("alice29.txt");
4 FileInfo fi2 = new FileInfo("asyoulik.txt");
5
6 using (CpioArchive archive = new CpioArchive())
7 {
8 archive.CreateEntry("alice29.txt", fi1);
9 archive.CreateEntry("asyoulik.txt", fi2);
10 archive.Save(cpioFile, format);
11 }
12}
Compressing cpio archive
In Unix-like operating systems cpio
utility allows compressing cpio archive to gzip on creation. Aspose.Zip provides similar functionality with the
SaveGzipped method.
1using (var archive = new CpioArchive())
2{
3 archive.CreateEntries(@"C:\folder", false);
4 archive.SaveGzipped("result.cpio.gz");
5}
Nowadays xz utility has become popular in Linux and Unix. Its compression of cpio is seamlessly integrated into Aspose.Zip. Use the SaveXzCompressed method of a cpio archive.
1using (var archive = new CpioArchive())
2{
3 archive.CreateEntries(@"C:\folder", false);
4 archive.SaveXzCompressed("result.cpio.xz");
5}