Skip to main content

Crate pna

Crate pna 

Source
Expand description

A library for more useful reading and writing PNA archives

Provides filesystem-related utilities in addition to the utilities necessary to manage PNA archives abstracted over a reader or writer hosted by libpna.

§pna

test Crates.io docs.rs

A pna archive reading/writing library for Rust.

# Cargo.toml
[dependencies]
pna = "0.34"

§Reading an archive

use pna::{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 pna::{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(())
}

§CLI

A command-line interface (CLI) is available. You can install it via Cargo or build from source.

§Via Cargo

cargo install portable-network-archive

§From Source (via Cargo)

cargo install --git https://github.com/ChanTsune/Portable-Network-Archive.git portable-network-archive

§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.

Modules§

fs
PNA filesystem utilities
prelude
PNA Prelude.

Structs§

Archive
Provides read and write access to a PNA file.
ChunkType
A 4-byte chunk type code.
CompressionLevel
Compression level of each algorithm.
Duration
A span of time with nanosecond precision.
EncodedDataReader
Reader for encoded entry data.
EntryBuilder
A builder for creating a NormalEntry.
EntryDataReader
Reader for Entry data.
EntryHeader
Represents the entry information header expressed in the FHED chunk.
EntryName
A UTF-8 encoded entry name.
EntryNameError
An error returned when an EntryName cannot be constructed from invalid input.
EntryPart
A structure representing the split Entry for archive splitting.
EntryReference
A UTF-8 encoded entry reference.
EntryReferenceError
An error returned when an EntryReference cannot be constructed from invalid input.
ExtendedAttribute
Represents a single extended attribute of a file entry.
HashAlgorithm
Password hash algorithm.
LengthExceeded
Error returned when a value exceeds the byte-length bound of a bounded owned string or byte slice.
Metadata
Metadata information about an entry.
NormalEntry
A normal entry in a PNA archive.
OwnerGid
Owner group id (fGId).
OwnerGroupName
Owner group name (fGNm).
OwnerGroupSid
Owner group SID (fGSi).
OwnerUid
Owner user id (fUId).
OwnerUserName
Owner user name (fONm).
OwnerUserSid
Owner user SID (fOSi).
PermissionDeprecated
Owner, group, and permission bits for an archive entry.
PermissionMode
POSIX permission mode (fMOd). Reserved bits outside 0o7777 (the rwx + setuid/setgid/sticky bits) are masked to 0 on construction.
RawChunk
A raw chunk in a PNA archive.
ReadOptions
Options for reading an entry.
ReadOptionsBuilder
Builder for ReadOptions.
SolidArchive
Provides write access to solid mode PNA files.
SolidEntry
A solid mode entry in a PNA archive.
SolidEntryBuilder
A builder for creating a SolidEntry.
SolidHeader
Represents the entry information header expressed in the SHED chunk.
UnknownValueError
Unknown value error.
WriteOptions
Options for writing entries to a PNA archive.
WriteOptionsBuilder
Builder for WriteOptions.
XattrName
Extended-attribute name identifier.
XattrValue
Extended-attribute value (arbitrary bytes).

Enums§

ChunkTypeError
ChunkType validation error.
CipherAlgorithm
Cipher algorithm.
CipherMode
Cipher mode of encryption algorithm.
Compression
Compression method.
DataKind
Type of filesystem object represented by an entry.
Encryption
Encryption algorithm.
LinkTargetType
Link target type for link entries.
ReadEntry
A NormalEntry or SolidEntry read from an archive.

Constants§

MIN_CHUNK_BYTES_SIZE
The minimum size of a PNA chunk in bytes.
PNA_HEADER
The magic number of Portable-Network-Archive.

Traits§

Chunk
A trait representing a chunk in a PNA archive.
Entry
A trait representing an entry in a PNA archive.

Functions§

read_as_chunks
Reads an archive as chunks from the given reader.
read_chunks_from_slice
Reads an archive as chunks from the given bytes.