#archive #data #crypto #codec #fs-file #pna

libpna

PNA(Portable-Network-Archive) decoding and encoding library

18 releases (9 breaking)

new 0.9.0 Apr 13, 2024
0.8.1 Mar 18, 2024
0.5.0 Dec 9, 2023
0.4.0 Nov 18, 2023
0.0.0-alpha.1 Mar 7, 2023

#473 in Data structures

Download history 95/week @ 2023-12-22 50/week @ 2023-12-29 9/week @ 2024-01-05 12/week @ 2024-01-12 29/week @ 2024-01-19 28/week @ 2024-01-26 52/week @ 2024-02-02 12/week @ 2024-02-09 275/week @ 2024-02-16 283/week @ 2024-02-23 235/week @ 2024-03-01 178/week @ 2024-03-08 250/week @ 2024-03-15 110/week @ 2024-03-22 61/week @ 2024-03-29 256/week @ 2024-04-05

684 downloads per month
Used in 2 crates (via pna)

Apache-2.0 OR MIT

185KB
4.5K SLoC

libpna

test Crates.io

A pna archive reading/writing library for Rust.

# Cargo.toml
[dependencies]
libpna = "0.9"

Reading an archive

use libpna::{Archive, ReadOption};
use std::fs::File;
use std::io::{self, copy, prelude::*};

fn main() -> io::Result<()> {
    let file = File::open("foo.pna")?;
    let mut archive = Archive::read_header(file)?;
    for entry in archive.entries_skip_solid() {
        let entry = entry?;
        let mut file = File::create(entry.header().path().as_path())?;
        let mut reader = entry.reader(ReadOption::builder().build())?;
        copy(&mut reader, &mut file)?;
    }
    Ok(())
}

Writing an archive

use libpna::{Archive, EntryBuilder, WriteOption};
use std::fs::File;
use std::io::{self, prelude::*};

fn main() -> io::Result<()> {
    let file = File::create("foo.pna")?;
    let mut archive = Archive::write_header(file)?;
    let mut entry_builder = EntryBuilder::new_file(
        "bar.txt".try_into().unwrap(),
        WriteOption::builder().build(),
    )?;
    entry_builder.write(b"content")?;
    let entry = entry_builder.build()?;
    archive.add_entry(entry)?;
    archive.finalize()?;
    Ok(())
}

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~8.5MB
~160K SLoC