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:
- Data is compressed according to
WriteOptionscompression settings - Compressed data is encrypted according to
WriteOptionsencryption settings - Encrypted data is buffered into chunks
- 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()consumesself) - Only entries with a
DataKind::FILEkind 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
impl OpaqueEntryBuilder
Sourcepub fn new(name: EntryName, kind: DataKind) -> Result<Self>
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.
Sourcepub fn new_with_options(
name: EntryName,
kind: DataKind,
option: impl WriteOption,
) -> Result<Self>
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.
Sourcepub const fn new_dir(name: EntryName) -> Self
👎Deprecated since 0.36.0: use DirEntryBuilder::new
pub const fn new_dir(name: EntryName) -> Self
use DirEntryBuilder::new
Creates a new OpaqueEntryBuilder for a directory entry.
Sourcepub fn new_file(name: EntryName, option: impl WriteOption) -> Result<Self>
👎Deprecated since 0.36.0: use FileEntryBuilder::new_with_options
pub fn new_file(name: EntryName, option: impl WriteOption) -> Result<Self>
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.
Sourcepub fn new_symlink(name: EntryName, source: EntryReference) -> Result<Self>
👎Deprecated since 0.36.0: use SymlinkEntryBuilder::new
pub fn new_symlink(name: EntryName, source: EntryReference) -> Result<Self>
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();Sourcepub fn new_hard_link(name: EntryName, source: EntryReference) -> Result<Self>
👎Deprecated since 0.36.0: use HardLinkEntryBuilder::new
pub fn new_hard_link(name: EntryName, source: EntryReference) -> Result<Self>
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();Sourcepub fn metadata(&mut self, metadata: Metadata) -> &mut Self
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.
Sourcepub fn created(
&mut self,
since_unix_epoch: impl Into<Option<Duration>>,
) -> &mut Self
👎Deprecated since 0.36.0: use OpaqueEntryBuilder::metadata with Metadata::with_*
pub fn created( &mut self, since_unix_epoch: impl Into<Option<Duration>>, ) -> &mut Self
use OpaqueEntryBuilder::metadata with Metadata::with_*
Sets the creation timestamp of the entry.
Sourcepub fn modified(
&mut self,
since_unix_epoch: impl Into<Option<Duration>>,
) -> &mut Self
👎Deprecated since 0.36.0: use OpaqueEntryBuilder::metadata with Metadata::with_*
pub fn modified( &mut self, since_unix_epoch: impl Into<Option<Duration>>, ) -> &mut Self
use OpaqueEntryBuilder::metadata with Metadata::with_*
Sets the last modified timestamp of the entry.
Sourcepub fn accessed(
&mut self,
since_unix_epoch: impl Into<Option<Duration>>,
) -> &mut Self
👎Deprecated since 0.36.0: use OpaqueEntryBuilder::metadata with Metadata::with_*
pub fn accessed( &mut self, since_unix_epoch: impl Into<Option<Duration>>, ) -> &mut Self
use OpaqueEntryBuilder::metadata with Metadata::with_*
Sets the last accessed timestamp of the entry.
Sourcepub 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
pub fn permission( &mut self, permission: impl Into<Option<Permission>>, ) -> &mut Self
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.
Sourcepub fn owner_uid(&mut self, value: impl Into<Option<OwnerUid>>) -> &mut Self
👎Deprecated since 0.36.0: use OpaqueEntryBuilder::metadata with Metadata::with_*
pub fn owner_uid(&mut self, value: impl Into<Option<OwnerUid>>) -> &mut Self
use OpaqueEntryBuilder::metadata with Metadata::with_*
Sets the owner user id facet (fUId).
Sourcepub fn owner_gid(&mut self, value: impl Into<Option<OwnerGid>>) -> &mut Self
👎Deprecated since 0.36.0: use OpaqueEntryBuilder::metadata with Metadata::with_*
pub fn owner_gid(&mut self, value: impl Into<Option<OwnerGid>>) -> &mut Self
use OpaqueEntryBuilder::metadata with Metadata::with_*
Sets the owner group id facet (fGId).
Sourcepub fn owner_user_name(
&mut self,
value: impl Into<Option<OwnerUserName>>,
) -> &mut Self
👎Deprecated since 0.36.0: use OpaqueEntryBuilder::metadata with Metadata::with_*
pub fn owner_user_name( &mut self, value: impl Into<Option<OwnerUserName>>, ) -> &mut Self
use OpaqueEntryBuilder::metadata with Metadata::with_*
Sets the owner user name facet (fONm).
Sourcepub fn owner_group_name(
&mut self,
value: impl Into<Option<OwnerGroupName>>,
) -> &mut Self
👎Deprecated since 0.36.0: use OpaqueEntryBuilder::metadata with Metadata::with_*
pub fn owner_group_name( &mut self, value: impl Into<Option<OwnerGroupName>>, ) -> &mut Self
use OpaqueEntryBuilder::metadata with Metadata::with_*
Sets the owner group name facet (fGNm).
Sourcepub fn owner_user_sid(
&mut self,
value: impl Into<Option<OwnerUserSid>>,
) -> &mut Self
👎Deprecated since 0.36.0: use OpaqueEntryBuilder::metadata with Metadata::with_*
pub fn owner_user_sid( &mut self, value: impl Into<Option<OwnerUserSid>>, ) -> &mut Self
use OpaqueEntryBuilder::metadata with Metadata::with_*
Sets the owner user SID facet (fOSi).
Sourcepub fn owner_group_sid(
&mut self,
value: impl Into<Option<OwnerGroupSid>>,
) -> &mut Self
👎Deprecated since 0.36.0: use OpaqueEntryBuilder::metadata with Metadata::with_*
pub fn owner_group_sid( &mut self, value: impl Into<Option<OwnerGroupSid>>, ) -> &mut Self
use OpaqueEntryBuilder::metadata with Metadata::with_*
Sets the owner group SID facet (fGSi).
Sourcepub fn permission_mode(
&mut self,
value: impl Into<Option<PermissionMode>>,
) -> &mut Self
👎Deprecated since 0.36.0: use OpaqueEntryBuilder::metadata with Metadata::with_*
pub fn permission_mode( &mut self, value: impl Into<Option<PermissionMode>>, ) -> &mut Self
use OpaqueEntryBuilder::metadata with Metadata::with_*
Sets the POSIX permission mode facet (fMOd).
Sourcepub fn link_target_type(
&mut self,
link_target_type: impl Into<Option<LinkTargetType>>,
) -> &mut Self
👎Deprecated since 0.36.0: use OpaqueEntryBuilder::metadata with Metadata::with_*
pub fn link_target_type( &mut self, link_target_type: impl Into<Option<LinkTargetType>>, ) -> &mut Self
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 symlinkSymbolicLink+Directory→ directory symlinkHardLink+File→ file hard linkHardLink+Directory→ directory hard link
Sourcepub fn file_size(&mut self, store: bool) -> &mut Self
👎Deprecated since 0.36.0: renamed to store_file_size
pub fn file_size(&mut self, store: bool) -> &mut Self
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.
Sourcepub fn store_file_size(&mut self, store: bool) -> &mut Self
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.
Sourcepub fn add_xattr(&mut self, xattr: ExtendedAttribute) -> &mut Self
👎Deprecated since 0.36.0: use OpaqueEntryBuilder::metadata with Metadata::with_xattrs
pub fn add_xattr(&mut self, xattr: ExtendedAttribute) -> &mut Self
use OpaqueEntryBuilder::metadata with Metadata::with_xattrs
Adds an ExtendedAttribute to the entry.
Sourcepub fn add_extra_chunk<T: Into<RawChunk>>(&mut self, chunk: T) -> &mut Self
pub fn add_extra_chunk<T: Into<RawChunk>>(&mut self, chunk: T) -> &mut Self
Adds extra chunk to the entry.
Sourcepub fn max_chunk_size(&mut self, size: NonZeroU32) -> &mut Self
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()?;Sourcepub fn build(self) -> Result<NormalEntry>
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
impl Write for OpaqueEntryBuilder
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)Auto Trait Implementations§
impl !Freeze for OpaqueEntryBuilder
impl !UnwindSafe for OpaqueEntryBuilder
impl RefUnwindSafe for OpaqueEntryBuilder
impl Send for OpaqueEntryBuilder
impl Sync for OpaqueEntryBuilder
impl Unpin for OpaqueEntryBuilder
impl UnsafeUnpin for OpaqueEntryBuilder
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> 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