CPIO composition

Overview

CPIO (Copy In, Copy Out) is an archive format primarily used in Unix-like operating systems for packaging multiple files and directories into a single archive. Although less commonly used than formats like TAR or ZIP, CPIO is still relevant in certain systems and workflows, especially for backup and software packaging. Aspose.ZIP provides support for creating and managing CPIO archives in .NET applications. You can package files into a CPIO archive by adding entries and saving the archive, similar to how you would work with other archive formats. 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.

 1    using (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.

1    using (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.

1    using (var archive = new CpioArchive())
2    {
3        archive.CreateEntries(@"C:\folder", false);
4        archive.SaveXzCompressed("result.cpio.xz");
5    }
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.