Skip to content

Commit f9b740d

Browse files
committed
📝 Expand documentation comment for EntryBuilder
1 parent e9469fd commit f9b740d

1 file changed

Lines changed: 79 additions & 3 deletions

File tree

lib/src/entry/builder.rs

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,54 @@ use std::{
2323

2424
/// A builder for creating a [`NormalEntry`].
2525
///
26-
/// This builder provides a flexible way to construct a `NormalEntry` by specifying
27-
/// its type (file, directory, symlink), content, and metadata. It handles the
28-
/// underlying complexity of compression and encryption.
26+
/// This builder provides a flexible way to construct entries for PNA archives by specifying
27+
/// the entry type (file, directory, symbolic link, hard link), content, and metadata.
28+
/// It handles compression and encryption transparently according to the provided [`WriteOptions`].
29+
///
30+
/// # Entry Types
31+
///
32+
/// - **Files**: Created with [`new_file()`](Self::new_file), support data writing via [`Write`] trait
33+
/// - **Directories**: Created with [`new_dir()`](Self::new_dir), have no data payload
34+
/// - **Symbolic links**: Created with [`new_symlink()`](Self::new_symlink), data is the link target path
35+
/// - **Hard links**: Created with [`new_hard_link()`](Self::new_hard_link), data is the link target path
36+
///
37+
/// # Write Trait Behavior
38+
///
39+
/// For **file entries**, the [`Write`] trait is fully functional. Data written via
40+
/// [`write_all()`](Write::write_all) or similar methods is automatically compressed and
41+
/// encrypted according to the [`WriteOptions`] provided at construction time. The original
42+
/// (uncompressed) file size is tracked separately.
43+
///
44+
/// For **directory entries**, the [`Write`] trait is implemented but writing data has no effect.
45+
/// Directories do not store data payloads in PNA archives.
46+
///
47+
/// For **symbolic link and hard link entries**, do not use the [`Write`] trait. Instead, the
48+
/// link target is provided to the constructor ([`new_symlink()`](Self::new_symlink) or
49+
/// [`new_hard_link()`](Self::new_hard_link)).
50+
///
51+
/// # Metadata
52+
///
53+
/// Metadata (timestamps, permissions, extended attributes) can be set at any time before
54+
/// calling [`build()`](Self::build). The order does not matter - you can set metadata before,
55+
/// during, or after writing data to file entries.
56+
///
57+
/// # Compression and Encryption
58+
///
59+
/// When data is written to a file entry:
60+
/// 1. Data is compressed according to [`WriteOptions`] compression settings
61+
/// 2. Compressed data is encrypted according to [`WriteOptions`] encryption settings
62+
/// 3. Encrypted data is buffered into chunks
63+
/// 4. Chunks are finalized when [`build()`](Self::build) is called
64+
///
65+
/// This happens **transparently** - you just write raw data and the builder handles the rest.
66+
///
67+
/// # Important Notes
68+
///
69+
/// - Each builder can only be built **once** ([`build()`](Self::build) consumes `self`)
70+
/// - File entries with no data written will have **zero size**
71+
/// - Compression and encryption are applied **during writes**, not at build time
72+
/// - The [`build()`](Self::build) method finalizes compression/encryption streams
73+
/// - Building a directory or file without calling write methods is valid
2974
///
3075
/// # Examples
3176
///
@@ -43,6 +88,21 @@ use std::{
4388
/// # }
4489
/// ```
4590
///
91+
/// ## Creating a file entry with extended attributes
92+
///
93+
/// ```
94+
/// # use std::io::{self, Write};
95+
/// use libpna::{EntryBuilder, WriteOptions, ExtendedAttribute};
96+
///
97+
/// # fn main() -> io::Result<()> {
98+
/// let mut builder = EntryBuilder::new_file("data.txt".into(), WriteOptions::store())?;
99+
/// builder.write_all(b"file content")?;
100+
/// builder.add_xattr(ExtendedAttribute::new("user.comment".into(), b"important".to_vec()));
101+
/// let entry = builder.build()?;
102+
/// # Ok(())
103+
/// # }
104+
/// ```
105+
///
46106
/// ## Creating a directory entry
47107
///
48108
/// ```
@@ -55,6 +115,22 @@ use std::{
55115
/// # Ok(())
56116
/// # }
57117
/// ```
118+
///
119+
/// ## Creating a symbolic link entry
120+
///
121+
/// ```
122+
/// # use std::io;
123+
/// use libpna::EntryBuilder;
124+
///
125+
/// # fn main() -> io::Result<()> {
126+
/// let builder = EntryBuilder::new_symlink(
127+
/// "link_name".into(),
128+
/// "target/file.txt".into()
129+
/// )?;
130+
/// let entry = builder.build()?;
131+
/// # Ok(())
132+
/// # }
133+
/// ```
58134
pub struct EntryBuilder {
59135
header: EntryHeader,
60136
phsf: Option<String>,

0 commit comments

Comments
 (0)