pub struct ChunkType(/* private fields */);Expand description
A 4-byte chunk type code.
PNA uses a chunk-based format inspired by PNG. Each chunk has a 4-character type code that determines how the chunk should be interpreted.
§Chunk Type Naming Convention
The case of each letter in the chunk type encodes important properties:
| Position | Uppercase | Lowercase |
|---|---|---|
| 1st | Critical (must understand) | Ancillary (can ignore) |
| 2nd | Public (standardized) | Private (application-specific) |
| 3rd | Reserved (must be uppercase) | - |
| 4th | Unsafe to copy | Safe to copy if unknown |
§Critical Chunks
These chunks are essential for reading the archive structure:
- Archive structure:
AHED(header),AEND(end),ANXT(next part) - Entry structure:
FHED(header),FDAT(data),FEND(end) - Solid mode:
SHED(header),SDAT(data),SEND(end) - Encryption:
PHSF(password hash string format)
§Ancillary Chunks
These chunks contain optional metadata that can be safely ignored:
- Timestamps:
cTIM,mTIM,aTIM(seconds),cTNS,mTNS,aTNS(nanoseconds) - File info:
fSIZ(size),fPRM(permissions) - Extended attributes:
xATR
§Creating Private Chunks
Use ChunkType::private to create application-specific chunk types:
use libpna::ChunkType;
// Private chunk type must have lowercase second letter
let my_chunk = ChunkType::private(*b"myTy").unwrap();
assert!(my_chunk.is_private());Implementations§
Source§impl ChunkType
impl ChunkType
Sourcepub const fn private(ty: [u8; 4]) -> Result<Self, ChunkTypeError>
pub const fn private(ty: [u8; 4]) -> Result<Self, ChunkTypeError>
Creates private ChunkType.
§Errors
This function will return an error in the following cases:
- Value contains non-ASCII alphabet characters
- The second character is not lowercase
- The third character is not uppercase
§Examples
assert!(ChunkType::private(*b"myTy").is_ok());
assert_eq!(
ChunkType::private(*b"zeR\0").unwrap_err(),
ChunkTypeError::NonAsciiAlphabetic
);
assert_eq!(
ChunkType::private(*b"pRIv").unwrap_err(),
ChunkTypeError::NonPrivateChunkType
);
assert_eq!(
ChunkType::private(*b"rese").unwrap_err(),
ChunkTypeError::Reserved
);Sourcepub const unsafe fn from_unchecked(ty: [u8; 4]) -> Self
pub const unsafe fn from_unchecked(ty: [u8; 4]) -> Self
Creates a custom ChunkType without validation.
§Panics
Panics if the chunk type contains non-UTF-8 characters and it is
formatted with Display.
let custom_chunk_type = unsafe { ChunkType::from_unchecked([0xe3, 0x81, 0x82, 0xe3]) };
format!("{}", custom_chunk_type);§Safety
Callers must ensure the value consists only of ASCII alphabetic characters (‘a’..‘z’ and ‘A’..‘Z’).
let custom_chunk_type = unsafe { ChunkType::from_unchecked(*b"myTy") };
format!("{}", custom_chunk_type);Sourcepub const fn is_critical(&self) -> bool
pub const fn is_critical(&self) -> bool
Returns true if the chunk is critical.
Sourcepub const fn is_private(&self) -> bool
pub const fn is_private(&self) -> bool
Returns true if the chunk is private.
Sourcepub const fn is_set_reserved(&self) -> bool
pub const fn is_set_reserved(&self) -> bool
Checks whether the reserved bit of the chunk name is set. If it is set, the chunk name is invalid.
Sourcepub const fn is_safe_to_copy(&self) -> bool
pub const fn is_safe_to_copy(&self) -> bool
Returns true if the chunk is safe to copy if unknown.
Trait Implementations§
Source§impl Ord for ChunkType
impl Ord for ChunkType
Source§impl PartialOrd for ChunkType
impl PartialOrd for ChunkType
impl Copy for ChunkType
impl Eq for ChunkType
impl StructuralPartialEq for ChunkType
Auto Trait Implementations§
impl Freeze for ChunkType
impl RefUnwindSafe for ChunkType
impl Send for ChunkType
impl Sync for ChunkType
impl Unpin for ChunkType
impl UnwindSafe for ChunkType
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