Skip to main content

Crate pna

Crate pna 

Source
Expand description

Filesystem utilities for reading and writing PNA archives.

Re-exports libpna and adds filesystem operations and extension traits.

§pna

test Crates.io docs.rs

A pna archive reading/writing library for Rust.

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

§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, FileEntryBuilder, 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 = FileEntryBuilder::new_with_options(
        "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§

bytes
Byte-slice primitives for parsing PNA archives.
fs
PNA filesystem utilities.
io
I/O primitives for reading and writing PNA archives.
prelude
PNA Prelude.

Structs§

Archive
A reader or writer for a PNA archive.
ChunkType
A 4-byte chunk type code.
CipherMode
Cipher mode of encryption algorithm.
Compression
Compression method.
CompressionLevel
A compression level interpreted by the selected algorithm.
DataKind
Type of filesystem object represented by an entry.
DirEntryBuilder
A builder for creating a directory NormalEntry.
EncodedDataReader
Reader for encoded entry data.
Encryption
Encryption algorithm.
EntryDataReader
A reader over decoded 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.
EntryPartDeprecated
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.
EntryWriteAttributes
Attributes known before streaming an entry payload.
ExtendedAttribute
Represents a single extended attribute of a file entry.
FileEntryBuilder
A builder for creating a regular file NormalEntry.
HardLinkEntryBuilder
A builder for creating a hard link NormalEntry.
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.
OpaqueEntryBuilder
A builder for an opaque NormalEntry with a specified DataKind.
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).
PermissionMode
POSIX permission mode (fMOd). Reserved bits outside 0o7777 (the rwx + setuid/setgid/sticky bits) are masked to 0 on construction.
RawChunk
A PNA chunk containing its length, type, data, and CRC32 checksum.
ReadOptions
Options for reading an entry.
ReadOptionsBuilder
Builder for ReadOptions.
SolidArchive
A writer for a PNA archive containing a single SolidEntry.
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.
SplitParts
A writer that splits archive chunks into parts of a bounded size.
SymlinkEntryBuilder
A builder for creating a symbolic link NormalEntry.
UnknownValueError
Unknown value error.
WriteOptions
Options for compressing and encrypting archive entries.
WriteOptionsBuilder
Builder for WriteOptions.
XattrName
Extended-attribute name identifier.
XattrValue
Extended-attribute value (arbitrary bytes).

Enums§

ChunkTypeError
ChunkType validation error.
CipherAlgorithm
Cipher algorithm.
EntryContent
Decoded content of a NormalEntry, interpreted according to its DataKind.
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.
MIN_SPLIT_PART_BYTES
Minimum accepted value for max_part_bytes (framing plus one minimal chunk).
PNA_HEADERDeprecated
Alias of PNA_SIGNATURE.
PNA_SIGNATURE
The signature at the beginning of every PNA archive.

Traits§

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

Functions§

read_as_chunks
Returns an iterator over the chunks of a PNA archive.
read_chunks_from_slice
Returns an iterator over the chunks of a PNA archive in a byte slice.

Type Aliases§

Duration
A SignedDuration under its original name.