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

libpna

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

26 releases (14 breaking)

new 0.14.1 Jul 25, 2024
0.13.0 Jun 22, 2024
0.8.1 Mar 18, 2024
0.5.0 Dec 9, 2023
0.0.0-alpha.1 Mar 7, 2023

#512 in Data structures

Download history 261/week @ 2024-04-04 220/week @ 2024-04-11 72/week @ 2024-04-18 253/week @ 2024-04-25 226/week @ 2024-05-02 239/week @ 2024-05-09 55/week @ 2024-05-16 92/week @ 2024-05-23 37/week @ 2024-05-30 224/week @ 2024-06-06 262/week @ 2024-06-13 251/week @ 2024-06-20 129/week @ 2024-06-27 426/week @ 2024-07-04 70/week @ 2024-07-11 39/week @ 2024-07-18

679 downloads per month
Used in 3 crates (via pna)

Apache-2.0 OR MIT

210KB
5K SLoC

libpna

test Crates.io

A pna archive reading/writing library for Rust.

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

Reading an archive

use libpna::{Archive, ReadOptions};
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(ReadOptions::builder().build())?;
        copy(&mut reader, &mut file)?;
    }
    Ok(())
}

Writing an archive

use libpna::{Archive, EntryBuilder, WriteOptions};
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".into(),
        WriteOptions::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