#cpio #archive #linux #deku #system

app librarium-cli

Library for the reading, creating, and modification of cpio file systems

3 unstable releases

0.3.1 Nov 9, 2024
0.3.0 Nov 9, 2024
0.2.0 Sep 27, 2024

#1390 in Filesystem

Download history 136/week @ 2024-09-22 31/week @ 2024-09-29 4/week @ 2024-10-06 6/week @ 2024-10-13 1/week @ 2024-10-20 90/week @ 2024-11-03 121/week @ 2024-11-10

212 downloads per month

MIT/Apache

40KB
721 lines

Librarium

github crates.io docs.rs build status Codecov

Library and binaries for the reading, creating, and modification of cpio archives.

Library

Compiler support: requires rustc 1.72.1+

Add the following to your Cargo.toml file:

[dependencies]
librarium = "0.3.0"

Read

use std::ffi::CString;
use std::io::Cursor;
use std::fs::{File, OpenOptions};
use librarium::{Header, ArchiveReader, NewcHeader, CpioReader, CpioHeader};
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

use std::ffi::CString;
use std::io::Cursor;
use std::fs::File;
use librarium::{Header, ArchiveWriter, NewcHeader};
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();

Binaries

Compiler support: requires rustc 1.77+

These are currently under development and are missing features, MR's welcome!

To install, run cargo install librarium-cli --locked, or download from the latest github release.

See --help for more information.

uncpio-librarium

tool to extract and list cpio filesystems

Usage: uncpio-librarium [OPTIONS] <ARCHIVE> <FORMAT>

Arguments:
  <ARCHIVE>  cpio path
  <FORMAT>   [possible values: odc, newc]

Options:
  -o, --offset <BYTES>   Skip BYTES at the start of FILESYSTEM [default: 0]
  -d, --dest <PATHNAME>  Extract to [PATHNAME] [default: out]
  -h, --help             Print help
  -V, --version          Print version

Dependencies

~5.5MB
~109K SLoC