Skip to main content

Crate librarium

Crate librarium 

Source
Expand description

Reader and Writer library for cpio archives

§Supported Formats

FormatMagicReadWrite
odc (Old ASCII)070707YesYes
newc (New ASCII / SVR4)070701YesYes
newc-crc (New CRC)070702YesYes

§Read

let mut file = File::open("archive.cpio").unwrap();
let mut archive = ArchiveReader::<NewcHeader>::from_reader_with_offset(&mut file, 0).unwrap();

// extract bytes from all in archive
for object in &archive.objects.inner {
    let mut out = OpenOptions::new()
        .write(true)
        .create(true)
        .open(object.header.as_header().name)
        .unwrap();
    archive.reader.extract_data(object, &mut out).unwrap();
}

§Write

let file = File::create("archive.cpio").unwrap();
let mut writer = ArchiveWriter::<NewcHeader>::new(Box::new(file));

// A
let a_data = "a\n".as_bytes();
let a_header = Header { name: "a".to_string(), ..Header::default()};
writer.push_file(Cursor::new(a_data), a_header).unwrap();

// write to archive
writer.write().unwrap();

§Features

  • std (enabled by default) — Enable std support
  • alloc (enabled by default) — Enable alloc support

Re-exports§

pub use cpio_header::CpioHeader;
pub use error::CpioError;
pub use read_seek::ReadSeek;
pub use newc::NewcCrcHeader;
pub use newc::NewcHeader;
pub use odc::OdcHeader;

Modules§

cpio_header
Trait for common cpio header operations.
error
Error types returned by this library.
newc
New ASCII (SVR4) cpio header formats (070701 and 070702).
odc
Old ASCII (odc) cpio header format (070707).
read_seek
Composable Read + Seek trait and helpers.

Structs§

ArchiveReader
Read cpio Archive and extract data
ArchiveWriter
Write cpio Archive and add data
Header
Format-independent representation of a cpio header.
Object
Single entry (header + data) in a cpio archive.
Objects
All objects in archive

Enums§

Data
Reader and Writer of data

Traits§

CpioReader
Extract data from cpio Archive
WriteSeek
Write + Seek