Skip to main content

OpaqueEntryBuilder

Struct OpaqueEntryBuilder 

Source
pub struct OpaqueEntryBuilder { /* private fields */ }
Expand description

A builder for creating a NormalEntry by writing an opaque byte stream tagged with a declared DataKind.

This is the escape hatch for DataKinds that have no dedicated builder: data written via the Write trait is compressed and encrypted according to the given WriteOptions and stored as-is, with no interpretation of its meaning. It also provides convenience constructors (new_dir(), new_file(), new_symlink(), new_hard_link()) for the kinds defined by the PNA specification, but for those kinds prefer the corresponding kind-specific builder instead (FileEntryBuilder, DirEntryBuilder, SymlinkEntryBuilder, HardLinkEntryBuilder), which encode that kind’s on-wire contract in the type itself. Reach for new() or new_with_options() directly only for kinds the specification does not define, such as private or experimental DataKinds.

§Write Trait Behavior

For entries constructed via new() or new_with_options() — writing the opaque byte stream for the declared DataKind — the Write trait is fully functional; the legacy new_file() constructor (which delegates to new_with_options() with DataKind::FILE) behaves the same way. Data written via write_all() or similar methods is automatically compressed and encrypted according to the WriteOptions provided at construction time. The original (uncompressed) size is tracked separately.

For directory entries (new_dir()), the Write trait is implemented but writing data has no effect. Directories do not store data payloads in PNA archives.

For symbolic link and hard link entries, do not use the Write trait. The link target is written internally when the entry is constructed via new_symlink() or new_hard_link(); writing further data onto the builder would corrupt it.

§Metadata

Metadata (timestamps, permissions, extended attributes) can be set at any time before calling build(). The order does not matter - you can set metadata before, during, or after writing data.

§Compression and Encryption

When data is written:

  1. Data is compressed according to WriteOptions compression settings
  2. Compressed data is encrypted according to WriteOptions encryption settings
  3. Encrypted data is buffered into chunks
  4. Chunks are finalized when build() is called

This happens transparently - you just write raw data and the builder handles the rest.

§Important Notes

  • Each builder can only be built once (build() consumes self)
  • Only entries with a DataKind::FILE kind record a raw file size; if no data is written, that size is recorded as zero. For all other kinds, the raw file size is omitted entirely
  • Compression and encryption are applied during writes, not at build time
  • The build() method finalizes compression/encryption streams
  • Building a directory or file without calling write methods is valid

Implementations§

Source§

impl OpaqueEntryBuilder

Source

pub fn new(name: EntryName, kind: DataKind) -> Result<Self>

Creates a builder for an entry of the given kind that stores its data without compression or encryption.

The entry data is written via the Write trait as an opaque byte stream; its interpretation is left to the application. Prefer the kind-specific builders for the kinds defined by the PNA specification.

§Errors

Returns an error if initialization fails.

Source

pub fn new_with_options( name: EntryName, kind: DataKind, option: impl WriteOption, ) -> Result<Self>

Creates a builder for an entry of the given kind with the given write options.

§Errors

Returns an error if initialization fails.

Source

pub const fn new_dir(name: EntryName) -> Self

👎Deprecated since 0.36.0:

use DirEntryBuilder::new

Creates a new OpaqueEntryBuilder for a directory entry.

Source

pub fn new_file(name: EntryName, option: impl WriteOption) -> Result<Self>

👎Deprecated since 0.36.0:

use FileEntryBuilder::new_with_options

Creates a new OpaqueEntryBuilder for a file entry with the given write options.

§Errors

Returns an error if initialization fails.

👎Deprecated since 0.36.0:

use SymlinkEntryBuilder::new

Creates a new OpaqueEntryBuilder for a symbolic link entry pointing to the given source.

§Errors

Returns an error if initialization fails.

§Examples
use libpna::{SymlinkEntryBuilder, EntryName, EntryReference};

let builder = SymlinkEntryBuilder::new(
    EntryName::try_from("path/of/link").unwrap(),
    EntryReference::try_from("path/of/target").unwrap(),
)
.unwrap();
let entry = builder.build().unwrap();
👎Deprecated since 0.36.0:

use HardLinkEntryBuilder::new

Creates a new OpaqueEntryBuilder for a hard link entry pointing to the given source.

§Errors

Returns an error if initialization fails.

§Examples
use libpna::{HardLinkEntryBuilder, EntryName, EntryReference};

let builder = HardLinkEntryBuilder::new(
    EntryName::try_from("path/of/link").unwrap(),
    EntryReference::try_from("path/of/target").unwrap(),
)
.unwrap();
let entry = builder.build().unwrap();
Source

pub fn metadata(&mut self, metadata: Metadata) -> &mut Self

Sets the metadata of the entry, replacing any previously set metadata.

The raw file size and compressed size recorded in the given metadata are ignored; build() computes them.

Source

pub fn created( &mut self, since_unix_epoch: impl Into<Option<Duration>>, ) -> &mut Self

👎Deprecated since 0.36.0:

use OpaqueEntryBuilder::metadata with Metadata::with_*

Sets the creation timestamp of the entry.

Source

pub fn modified( &mut self, since_unix_epoch: impl Into<Option<Duration>>, ) -> &mut Self

👎Deprecated since 0.36.0:

use OpaqueEntryBuilder::metadata with Metadata::with_*

Sets the last modified timestamp of the entry.

Source

pub fn accessed( &mut self, since_unix_epoch: impl Into<Option<Duration>>, ) -> &mut Self

👎Deprecated since 0.36.0:

use OpaqueEntryBuilder::metadata with Metadata::with_*

Sets the last accessed timestamp of the entry.

Source

pub fn permission( &mut self, permission: impl Into<Option<Permission>>, ) -> &mut Self

👎Deprecated since 0.34.0:

the fPRM chunk is superseded by the owner facet chunks; use OpaqueEntryBuilder::metadata with Metadata::with_owner_uid/with_owner_gid/with_owner_user_name/with_owner_group_name/with_permission_mode

Sets the permission of the entry to the given owner, group, and permissions.

Source

pub fn owner_uid(&mut self, value: impl Into<Option<OwnerUid>>) -> &mut Self

👎Deprecated since 0.36.0:

use OpaqueEntryBuilder::metadata with Metadata::with_*

Sets the owner user id facet (fUId).

Source

pub fn owner_gid(&mut self, value: impl Into<Option<OwnerGid>>) -> &mut Self

👎Deprecated since 0.36.0:

use OpaqueEntryBuilder::metadata with Metadata::with_*

Sets the owner group id facet (fGId).

Source

pub fn owner_user_name( &mut self, value: impl Into<Option<OwnerUserName>>, ) -> &mut Self

👎Deprecated since 0.36.0:

use OpaqueEntryBuilder::metadata with Metadata::with_*

Sets the owner user name facet (fONm).

Source

pub fn owner_group_name( &mut self, value: impl Into<Option<OwnerGroupName>>, ) -> &mut Self

👎Deprecated since 0.36.0:

use OpaqueEntryBuilder::metadata with Metadata::with_*

Sets the owner group name facet (fGNm).

Source

pub fn owner_user_sid( &mut self, value: impl Into<Option<OwnerUserSid>>, ) -> &mut Self

👎Deprecated since 0.36.0:

use OpaqueEntryBuilder::metadata with Metadata::with_*

Sets the owner user SID facet (fOSi).

Source

pub fn owner_group_sid( &mut self, value: impl Into<Option<OwnerGroupSid>>, ) -> &mut Self

👎Deprecated since 0.36.0:

use OpaqueEntryBuilder::metadata with Metadata::with_*

Sets the owner group SID facet (fGSi).

Source

pub fn permission_mode( &mut self, value: impl Into<Option<PermissionMode>>, ) -> &mut Self

👎Deprecated since 0.36.0:

use OpaqueEntryBuilder::metadata with Metadata::with_*

Sets the POSIX permission mode facet (fMOd).

👎Deprecated since 0.36.0:

use OpaqueEntryBuilder::metadata with Metadata::with_*

Sets the link target type for link entries.

Combined with DataKind, this determines the link type:

  • SymbolicLink + File → file symlink
  • SymbolicLink + Directory → directory symlink
  • HardLink + File → file hard link
  • HardLink + Directory → directory hard link
Source

pub fn file_size(&mut self, store: bool) -> &mut Self

👎Deprecated since 0.36.0:

renamed to store_file_size

Sets whether to store the raw file size in the entry metadata.

When true, the raw file size is recorded; when false, it is omitted.

Source

pub fn store_file_size(&mut self, store: bool) -> &mut Self

Sets whether to store the raw file size in the entry metadata.

The size is recorded only for entries whose data kind is DataKind::FILE. When true (the default), the raw file size is recorded for such entries; when false, it is omitted.

Source

pub fn add_xattr(&mut self, xattr: ExtendedAttribute) -> &mut Self

👎Deprecated since 0.36.0:

use OpaqueEntryBuilder::metadata with Metadata::with_xattrs

Adds an ExtendedAttribute to the entry.

Source

pub fn add_extra_chunk<T: Into<RawChunk>>(&mut self, chunk: T) -> &mut Self

Adds extra chunk to the entry.

Source

pub fn max_chunk_size(&mut self, size: NonZeroU32) -> &mut Self

Sets the maximum chunk size for data written to this entry.

The default is the maximum allowed chunk size (~4GB).

§Examples
use std::num::NonZeroU32;
use libpna::{OpaqueEntryBuilder, DataKind, WriteOptions};

let mut builder =
    OpaqueEntryBuilder::new_with_options("data.bin".into(), DataKind::FILE, WriteOptions::store())?;
builder.max_chunk_size(NonZeroU32::new(1024 * 1024).unwrap()); // 1MB chunks
builder.write_all(b"file content")?;
let entry = builder.build()?;
Source

pub fn build(self) -> Result<NormalEntry>

Consumes this builder and returns the constructed NormalEntry.

§Errors

Returns an error if an I/O error occurs while building entry into buffer.

Trait Implementations§

Source§

impl Write for OpaqueEntryBuilder

Source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

Writes a buffer into this writer, returning how many bytes were written. Read more
Source§

fn flush(&mut self) -> Result<()>

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
1.36.0 · Source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
Source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations§

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> 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, 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