CPIO
CPIO (Copy In, Copy Out) is a file archiver utility and its associated file format. It is primarily used on Unix-like operating systems for creating archives of files and directories. The CPIO format supports various sub-formats including the new ASCII format, old ASCII format, and old binary format.
Here is a simple example of how to use Compress4J to create and extract CPIO files:
Example Usage
CPIO Creation
try (CpioArchiveCreator cpioCreator = CpioArchiveCreator.builder(Path.of("example.cpio"))
.format(CpioFormat.NEW)
.blockSize(1024)
.encoding(UTF_8)
.filter(s -> !s.name().endsWith("temp.txt"))
.build()) {
cpioCreator.add(EntrySource.file("document.txt", Path.of("path/to/document.txt")));
cpioCreator.add(EntrySource.directory("subdir/"));
cpioCreator.add(EntrySource.file("subdir/nested.txt", Path.of("path/to/nested.txt")));
cpioCreator.addDirectoryRecursively(Path.of("sourceDir"));
}
CPIO Extraction
try (CpioArchiveExtractor cpioExtractor = CpioArchiveExtractor.builder(Path.of("example.cpio"))
.blockSize(1024)
.encoding(UTF_8)
.filter(entry -> !entry.name().startsWith("temp"))
.errorHandler((entry, failure) -> entry.name().endsWith(".tmp") ? SKIP : ABORT)
.escapingSymlinkPolicy(EscapingSymlinkPolicy.DISALLOW)
.postProcessor((entry, exception) -> {})
.stripComponents(1)
.overwrite(true)
.build()) {
cpioExtractor.extract(Path.of("outputDir"));
}