Expand description
A library for reading and writing PNA archives.
The APIs operate over readers and writers and support streaming archive data without loading an entire archive into memory.
§Quick Start
§Creating an Archive
use libpna::{Archive, DirEntryBuilder, FileEntryBuilder, WriteOptions};
use std::fs::File;
use std::io::{self, Write};
fn main() -> io::Result<()> {
let file = File::create("archive.pna")?;
let mut archive = Archive::write_header(file)?;
// Add a file entry
let mut entry = FileEntryBuilder::new_with_options(
"hello.txt".into(),
WriteOptions::builder().build(),
)?;
entry.write_all(b"Hello, world!")?;
archive.add_entry(entry.build()?)?;
// Add a directory entry
let dir = DirEntryBuilder::new("my_folder/".into());
archive.add_entry(dir.build()?)?;
archive.finalize()?;
Ok(())
}§Reading an Archive
use libpna::{Archive, ReadEntry, ReadOptions};
use std::fs::File;
use std::io::{self, Read};
fn main() -> io::Result<()> {
let file = File::open("archive.pna")?;
let mut archive = Archive::read_header(file)?;
for entry in archive.entries().skip_solid() {
let entry = entry?;
println!("Entry: {}", entry.header().path().as_path().display());
// Read file contents
let mut reader = entry.reader(ReadOptions::builder().build())?;
let mut contents = Vec::new();
reader.read_to_end(&mut contents)?;
}
Ok(())
}§Compression and Encryption
PNA supports multiple compression algorithms and encryption options:
use libpna::{CipherMode, Compression, Encryption, HashAlgorithm, WriteOptions};
// Compressed entry (Zstandard)
let compressed = WriteOptions::builder()
.compression(Compression::ZSTANDARD)
.build();
// Encrypted entry (AES-256-GCM with Argon2id key derivation)
let encrypted = WriteOptions::builder()
.compression(Compression::ZSTANDARD)
.encryption(Encryption::AES)
.cipher_mode(CipherMode::GCM)
.hash_algorithm(HashAlgorithm::argon2id())
.password(Some("secure_password"))
.build();§Solid Mode
Solid mode compresses multiple files together for better compression ratios:
use libpna::{Archive, FileEntryBuilder, SolidEntryBuilder, WriteOptions};
use std::io::{self, Write};
fn main() -> io::Result<()> {
let mut archive = Archive::write_header(Vec::new())?;
// Create a solid entry containing multiple files
let mut solid = SolidEntryBuilder::new(WriteOptions::builder().build())?;
let mut file1 = FileEntryBuilder::new("file1.txt".into())?;
file1.write_all(b"Content 1")?;
solid.add_entry(file1.build()?)?;
let mut file2 = FileEntryBuilder::new("file2.txt".into())?;
file2.write_all(b"Content 2")?;
solid.add_entry(file2.build()?)?;
archive.add_entry(solid.build()?)?;
archive.finalize()?;
Ok(())
}§Key Types
Archive- Main entry point for reading and writing archivesFileEntryBuilder/DirEntryBuilder/SymlinkEntryBuilder/HardLinkEntryBuilder- Kind-specific entry buildersOpaqueEntryBuilder- Escape-hatch builder for entry kinds without a dedicated builderSolidEntryBuilder- Builder for creating solid (multi-file) entriesEntryWriteAttributes- Metadata and extra chunks for streaming entry writesWriteOptions- Configuration for compression and encryption when writingReadOptions- Configuration (password) for reading encrypted entriesNormalEntry/SolidEntry/ReadEntry- Entry types for readingChunk/ChunkType- Low-level chunk primitives
§Feature Flags
zlib-ng- Use zlib-ng for improved deflate compression performanceunstable-async- Enable async I/O support viafutures-io(unstable API)
Modules§
- bytes
- Byte-slice primitives for parsing PNA archives.
- io
- I/O primitives for reading and writing PNA archives.
- prelude
- PNA Prelude.
Structs§
- Archive
- A reader or writer for a PNA archive.
- Chunk
Type - A 4-byte chunk type code.
- Cipher
Mode - Cipher mode of encryption algorithm.
- Compression
- Compression method.
- Compression
Level - A compression level interpreted by the selected algorithm.
- Data
Kind - Type of filesystem object represented by an entry.
- DirEntry
Builder - A builder for creating a directory
NormalEntry. - Encoded
Data Reader - Reader for encoded entry data.
- Encryption
- Encryption algorithm.
- Entry
Data Reader - A reader over decoded entry data.
- Entry
Header - Represents the entry information header expressed in the
FHEDchunk. - Entry
Name - A UTF-8 encoded entry name.
- Entry
Name Error - An error returned when an
EntryNamecannot be constructed from invalid input. - Entry
Part Deprecated - A structure representing the split
Entryfor archive splitting. - Entry
Reference - A UTF-8 encoded entry reference.
- Entry
Reference Error - An error returned when an
EntryReferencecannot be constructed from invalid input. - Entry
Write Attributes - Attributes known before streaming an entry payload.
- Extended
Attribute - Represents a single extended attribute of a file entry.
- File
Entry Builder - A builder for creating a regular file
NormalEntry. - Hard
Link Entry Builder - A builder for creating a hard link
NormalEntry. - Hash
Algorithm - Password hash algorithm.
- Length
Exceeded - Error returned when a value exceeds the byte-length bound of a bounded owned string or byte slice.
- Metadata
- Metadata information about an entry.
- Normal
Entry - A normal entry in a PNA archive.
- Opaque
Entry Builder - A builder for an opaque
NormalEntrywith a specifiedDataKind. - Owner
Gid - Owner group id (
fGId). - Owner
Group Name - Owner group name (
fGNm). - Owner
Group Sid - Owner group SID (
fGSi). - Owner
Uid - Owner user id (
fUId). - Owner
User Name - Owner user name (
fONm). - Owner
User Sid - Owner user SID (
fOSi). - Permission
Mode - POSIX permission mode (
fMOd). Reserved bits outside0o7777(the rwx + setuid/setgid/sticky bits) are masked to 0 on construction. - RawChunk
- A PNA chunk containing its length, type, data, and CRC32 checksum.
- Read
Options - Options for reading an entry.
- Read
Options Builder - Builder for
ReadOptions. - Solid
Archive - A writer for a PNA archive containing a single
SolidEntry. - Solid
Entry - A solid mode entry in a PNA archive.
- Solid
Entry Builder - A builder for creating a
SolidEntry. - Solid
Header - Represents the entry information header expressed in the
SHEDchunk. - Split
Parts - A writer that splits archive chunks into parts of a bounded size.
- Symlink
Entry Builder - A builder for creating a symbolic link
NormalEntry. - Unknown
Value Error - Unknown value error.
- Write
Options - Options for compressing and encrypting archive entries.
- Write
Options Builder - Builder for
WriteOptions. - Xattr
Name - Extended-attribute name identifier.
- Xattr
Value - Extended-attribute value (arbitrary bytes).
Enums§
- Chunk
Type Error ChunkTypevalidation error.- Cipher
Algorithm - Cipher algorithm.
- Entry
Content - Decoded content of a
NormalEntry, interpreted according to itsDataKind. - Link
Target Type - Link target type for link entries.
- Read
Entry - A
NormalEntryorSolidEntryread 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_
HEADER Deprecated - Alias of
PNA_SIGNATURE. - PNA_
SIGNATURE - The signature at the beginning of every PNA archive.
Traits§
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
SignedDurationunder its original name.