Skip to main content

NormalEntry

Struct NormalEntry 

Source
pub struct NormalEntry<T = Vec<u8>> { /* private fields */ }
Expand description

A normal entry in a PNA archive.

Normal entries represent individual files in the archive, allowing for random access to the file data. Each entry includes a header, optional password hash, data chunks, metadata, extended attributes, and any extra chunks.

Implementations§

Source§

impl<T> NormalEntry<T>

Source

pub fn header(&self) -> &EntryHeader

Returns the header of this entry.

Source

pub fn name(&self) -> &EntryName

Returns the name of this entry.

§Warning

The returned name is not sanitized. Using it directly as a filesystem path may allow path traversal. Call EntryName::sanitize before using it as a path.

Source

pub const fn data_kind(&self) -> DataKind

Returns the data kind of this entry.

Source

pub const fn compression(&self) -> Compression

Returns the compression method of this entry.

Source

pub const fn encryption(&self) -> Encryption

Returns the encryption method of this entry.

Source

pub const fn cipher_mode(&self) -> CipherMode

Returns the cipher mode of this entry’s encryption method.

Source

pub fn metadata(&self) -> &Metadata

Returns the metadata of this entry.

Source

pub fn xattrs(&self) -> &[ExtendedAttribute]

Returns the extended attributes of this entry.

Source

pub fn extra_chunks(&self) -> &[RawChunk<T>]

Returns the extra chunks of this entry.

Source

pub fn with_metadata(self, metadata: Metadata) -> NormalEntry<T>

Applies metadata to the entry.

§Examples
use libpna::{EntryBuilder, Metadata};

let mut entry = EntryBuilder::new_dir("dir_entry".into()).build()?;
entry.with_metadata(Metadata::new());
Source

pub fn with_xattrs( self, xattrs: impl Into<Vec<ExtendedAttribute>>, ) -> NormalEntry<T>

Applies extended attributes to the entry.

§Examples
use libpna::{EntryBuilder, ExtendedAttribute, XattrName, XattrValue};

let mut entry = EntryBuilder::new_dir("dir_entry".into()).build()?;
entry.with_xattrs(&[ExtendedAttribute::new(
    XattrName::try_from("key").unwrap(),
    XattrValue::try_from(b"value".as_slice()).unwrap(),
)]);
Source

pub fn with_name(self, name: EntryName) -> NormalEntry<T>

Applies a new name to the entry, preserving all other fields.

This is useful for path transformations during archive-to-archive copying where the entry data should remain unchanged.

§Examples
use libpna::EntryBuilder;

let entry = EntryBuilder::new_dir("original/path".into()).build()?;
let renamed = entry.with_name("new/path".into());
assert_eq!(renamed.header().path().as_str(), "new/path");
Source§

impl<T> NormalEntry<T>
where T: Clone,

Source

pub fn with_extra_chunks( self, chunks: impl Into<Vec<RawChunk<T>>>, ) -> NormalEntry<T>

Applies extra chunks to the entry.

§Examples
use libpna::{ChunkType, EntryBuilder, RawChunk};

let mut entry = EntryBuilder::new_dir("dir_entry".into()).build()?;
entry.with_extra_chunks(&[RawChunk::from_data(
    ChunkType::private(*b"myTy").unwrap(),
    b"some data",
)]);
Source§

impl<T> NormalEntry<T>
where T: AsRef<[u8]>,

Source

pub fn encoded_reader(&self) -> EncodedDataReader<'_>

Returns a reader over the encoded FDAT chunk body bytes.

This reader exposes the entry data as stored in the archive, before decryption or decompression. It returns the concatenated bodies of all FDAT chunks and does not include chunk length, type, or CRC bytes.

Source

pub fn reader( &self, option: impl ReadOption, ) -> Result<EntryDataReader<'_>, Error>

Returns the reader of this NormalEntry.

§Errors

Returns an error if an I/O error occurs while reading from the reader.

§Examples
use libpna::{Archive, ReadOptions};
use std::{fs, io};

let file = fs::File::open("foo.pna")?;
let mut archive = Archive::read_header(file)?;
for entry in archive.entries().skip_solid() {
    let entry = entry?;
    let mut reader = entry.reader(ReadOptions::builder().build())?;
    let name = entry.header().path();
    let mut dist_file = fs::File::create(name)?;
    io::copy(&mut reader, &mut dist_file)?;
}

Trait Implementations§

Source§

impl<T> Clone for NormalEntry<T>
where T: Clone,

Source§

fn clone(&self) -> NormalEntry<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for NormalEntry<T>
where T: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl EntryFsExt for NormalEntry

Source§

fn from_path<P: AsRef<Path>>(path: P) -> Result<Self>

Creates an entry from the given path.

The path may refer to a regular file or a directory. For files, the file contents are read and embedded into the resulting entry using default WriteOptions (equivalent to WriteOptions::builder().build()). For directories, an empty directory entry is created. Symlinks are followed (uses std::fs::metadata). If the intention is to archive a symbolic link itself, use EntryBuilder::new_symlink.

§Examples
use pna::NormalEntry;
use pna::prelude::*;

NormalEntry::from_path("path/to/file")?;
§Errors

Returns an error if an I/O error occurs while creating the entry.

Source§

fn from_path_with<P: AsRef<Path>>( path: P, options: WriteOptions, ) -> Result<Self>
where Self: Sized,

Creates an entry from the given path with options.

Behaves like EntryFsExt::from_path, but uses the provided WriteOptions when constructing a file entry.

§Examples
use pna::prelude::*;
use pna::{NormalEntry, WriteOptions};

NormalEntry::from_path_with("path/to/file", WriteOptions::store())?;
§Errors

Returns an error if an I/O error occurs while creating the entry.

Creates an entry from the given path without following symlinks.

This behaves like EntryFsExt::from_path, but uses std::fs::symlink_metadata to avoid following symbolic links. When path is a symbolic link, a symbolic-link entry is created using EntryBuilder::new_symlink, with the link target captured via std::fs::read_link. For regular files and directories, behavior is identical to EntryFsExt::from_path.

§Examples
use pna::NormalEntry;
use pna::prelude::*;

NormalEntry::from_path_symlink("path/to/file")?;
§Errors

Returns an error if an I/O error occurs while creating the entry.

Creates an entry from the given path with options, without following symlinks.

Behaves like EntryFsExt::from_path_with, but uses std::fs::symlink_metadata and creates a symbolic-link entry for symlinks instead of following them.

§Examples
use pna::prelude::*;
use pna::{NormalEntry, WriteOptions};

NormalEntry::from_path_symlink_with("path/to/file", WriteOptions::store())?;
§Errors

Returns an error if an I/O error occurs while creating the entry.

Source§

impl<'a> From<NormalEntry<&'a [u8]>> for NormalEntry

Source§

fn from(value: NormalEntry<&'a [u8]>) -> NormalEntry

Converts to this type from the input type.
Source§

impl<'a> From<NormalEntry<&'a [u8]>> for NormalEntry<Cow<'a, [u8]>>

Source§

fn from(value: NormalEntry<&'a [u8]>) -> NormalEntry<Cow<'a, [u8]>>

Converts to this type from the input type.
Source§

impl<'a> From<NormalEntry<Cow<'a, [u8]>>> for NormalEntry

Source§

fn from(value: NormalEntry<Cow<'a, [u8]>>) -> NormalEntry

Converts to this type from the input type.
Source§

impl<T> From<NormalEntry<T>> for ReadEntry<T>

Source§

fn from(value: NormalEntry<T>) -> ReadEntry<T>

Converts to this type from the input type.
Source§

impl From<NormalEntry> for NormalEntry<Cow<'_, [u8]>>

Source§

fn from(value: NormalEntry) -> NormalEntry<Cow<'_, [u8]>>

Converts to this type from the input type.
Source§

impl<T> Hash for NormalEntry<T>
where T: Hash,

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> Ord for NormalEntry<T>
where T: Ord,

Source§

fn cmp(&self, other: &NormalEntry<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T> PartialEq for NormalEntry<T>
where T: PartialEq,

Source§

fn eq(&self, other: &NormalEntry<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialOrd for NormalEntry<T>
where T: PartialOrd,

Source§

fn partial_cmp(&self, other: &NormalEntry<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> TryFrom<RawEntry<T>> for NormalEntry<T>
where RawChunk<T>: Chunk,

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from( entry: RawEntry<T>, ) -> Result<NormalEntry<T>, <NormalEntry<T> as TryFrom<RawEntry<T>>>::Error>

Performs the conversion.
Source§

impl<T> Entry for NormalEntry<T>
where NormalEntry<T>: SealedEntryExt,

Source§

impl<T> Eq for NormalEntry<T>
where T: Eq,

Source§

impl<T> StructuralPartialEq for NormalEntry<T>

Auto Trait Implementations§

§

impl<T = Vec<u8>> !Freeze for NormalEntry<T>

§

impl<T> RefUnwindSafe for NormalEntry<T>
where T: RefUnwindSafe,

§

impl<T> Send for NormalEntry<T>
where T: Send,

§

impl<T> Sync for NormalEntry<T>
where T: Sync,

§

impl<T> Unpin for NormalEntry<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for NormalEntry<T>

§

impl<T> UnwindSafe for NormalEntry<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V