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>
impl<T> NormalEntry<T>
Sourcepub fn header(&self) -> &EntryHeader
pub fn header(&self) -> &EntryHeader
Returns the header of this entry.
Sourcepub fn name(&self) -> &EntryName
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.
Sourcepub const fn compression(&self) -> Compression
pub const fn compression(&self) -> Compression
Returns the compression method of this entry.
Sourcepub const fn encryption(&self) -> Encryption
pub const fn encryption(&self) -> Encryption
Returns the encryption method of this entry.
Sourcepub const fn cipher_mode(&self) -> CipherMode
pub const fn cipher_mode(&self) -> CipherMode
Returns the cipher mode of this entry’s encryption method.
Sourcepub fn xattrs(&self) -> &[ExtendedAttribute]
pub fn xattrs(&self) -> &[ExtendedAttribute]
Returns the extended attributes of this entry.
Sourcepub fn extra_chunks(&self) -> &[RawChunk<T>]
pub fn extra_chunks(&self) -> &[RawChunk<T>]
Returns the extra chunks of this entry.
Sourcepub fn with_metadata(self, metadata: Metadata) -> NormalEntry<T>
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());Sourcepub fn with_xattrs(
self,
xattrs: impl Into<Vec<ExtendedAttribute>>,
) -> NormalEntry<T>
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(),
)]);Sourcepub fn with_name(self, name: EntryName) -> NormalEntry<T>
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,
impl<T> NormalEntry<T>where
T: Clone,
Sourcepub fn with_extra_chunks(
self,
chunks: impl Into<Vec<RawChunk<T>>>,
) -> NormalEntry<T>
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>
impl<T> NormalEntry<T>
Sourcepub fn encoded_reader(&self) -> EncodedDataReader<'_> ⓘ
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.
Sourcepub fn reader(
&self,
option: impl ReadOption,
) -> Result<EntryDataReader<'_>, Error>
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,
impl<T> Clone for NormalEntry<T>where
T: Clone,
Source§fn clone(&self) -> NormalEntry<T>
fn clone(&self) -> NormalEntry<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T> Debug for NormalEntry<T>where
T: Debug,
impl<T> Debug for NormalEntry<T>where
T: Debug,
Source§impl EntryFsExt for NormalEntry
impl EntryFsExt for NormalEntry
Source§fn from_path<P: AsRef<Path>>(path: P) -> Result<Self>
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,
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.
Source§fn from_path_symlink<P: AsRef<Path>>(path: P) -> Result<Self>where
Self: Sized,
fn from_path_symlink<P: AsRef<Path>>(path: P) -> Result<Self>where
Self: Sized,
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.
Source§fn from_path_symlink_with<P: AsRef<Path>>(
path: P,
options: WriteOptions,
) -> Result<Self>where
Self: Sized,
fn from_path_symlink_with<P: AsRef<Path>>(
path: P,
options: WriteOptions,
) -> Result<Self>where
Self: Sized,
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
impl<'a> From<NormalEntry<&'a [u8]>> for NormalEntry
Source§fn from(value: NormalEntry<&'a [u8]>) -> NormalEntry
fn from(value: NormalEntry<&'a [u8]>) -> NormalEntry
Source§impl<'a> From<NormalEntry<&'a [u8]>> for NormalEntry<Cow<'a, [u8]>>
impl<'a> From<NormalEntry<&'a [u8]>> for NormalEntry<Cow<'a, [u8]>>
Source§fn from(value: NormalEntry<&'a [u8]>) -> NormalEntry<Cow<'a, [u8]>>
fn from(value: NormalEntry<&'a [u8]>) -> NormalEntry<Cow<'a, [u8]>>
Source§impl<'a> From<NormalEntry<Cow<'a, [u8]>>> for NormalEntry
impl<'a> From<NormalEntry<Cow<'a, [u8]>>> for NormalEntry
Source§fn from(value: NormalEntry<Cow<'a, [u8]>>) -> NormalEntry
fn from(value: NormalEntry<Cow<'a, [u8]>>) -> NormalEntry
Source§impl<T> From<NormalEntry<T>> for ReadEntry<T>
impl<T> From<NormalEntry<T>> for ReadEntry<T>
Source§fn from(value: NormalEntry<T>) -> ReadEntry<T>
fn from(value: NormalEntry<T>) -> ReadEntry<T>
Source§impl From<NormalEntry> for NormalEntry<Cow<'_, [u8]>>
impl From<NormalEntry> for NormalEntry<Cow<'_, [u8]>>
Source§fn from(value: NormalEntry) -> NormalEntry<Cow<'_, [u8]>>
fn from(value: NormalEntry) -> NormalEntry<Cow<'_, [u8]>>
Source§impl<T> Hash for NormalEntry<T>where
T: Hash,
impl<T> Hash for NormalEntry<T>where
T: Hash,
Source§impl<T> Ord for NormalEntry<T>where
T: Ord,
impl<T> Ord for NormalEntry<T>where
T: Ord,
Source§fn cmp(&self, other: &NormalEntry<T>) -> Ordering
fn cmp(&self, other: &NormalEntry<T>) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T> PartialEq for NormalEntry<T>where
T: PartialEq,
impl<T> PartialEq for NormalEntry<T>where
T: PartialEq,
Source§fn eq(&self, other: &NormalEntry<T>) -> bool
fn eq(&self, other: &NormalEntry<T>) -> bool
self and other values to be equal, and is used by ==.Source§impl<T> PartialOrd for NormalEntry<T>where
T: PartialOrd,
impl<T> PartialOrd for NormalEntry<T>where
T: PartialOrd,
Source§impl<T> TryFrom<RawEntry<T>> for NormalEntry<T>
impl<T> TryFrom<RawEntry<T>> for NormalEntry<T>
impl<T> Entry for NormalEntry<T>where
NormalEntry<T>: SealedEntryExt,
impl<T> Eq for NormalEntry<T>where
T: Eq,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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