Skip to main content

PackPlan

Struct PackPlan 

Source
pub struct PackPlan {
    pub root_name: String,
    pub file_count: usize,
    pub dir_count: usize,
    pub link_count: usize,
    pub skipped: Vec<SkippedEntry>,
    pub total_size: u64,
    /* private fields */
}
Expand description

流式打包的计划:遍历一遍目录,只取大小,不读内容。

pack_folder 把所有文件内容拼进一个内存载荷,几十 GB 的文件夹在手机上 根本加密不了。流式打包分三步:plan_folder 定下条目与偏移(索引长度从此 确定,只差逐文件哈希)→ PackPlan::reader 按同样的顺序把文件内容串成 一条 Read 流,边读边算哈希 → PackPlan::finish 填入哈希得到真索引。 配合 crate::file::encrypt_stream 的定稿回调使用。

Fields§

§root_name: String

容器根名。

§file_count: usize

普通文件数。

§dir_count: usize

目录数。

§link_count: usize

符号链接数。

§skipped: Vec<SkippedEntry>

跳过的条目。

§total_size: u64

所有文件内容的总字节数(即容器载荷的明文长度)。

Implementations§

Source§

impl PackPlan

Source

pub fn placeholder_index(&self) -> Result<Vec<u8>>

与最终索引等长的占位索引(哈希全零),用来给流式加密预留头部空间。

§Errors

条目非法时返回。

Source

pub fn finish(&self, hashes: &[[u8; 32]]) -> Result<ContainerIndex>

填入逐文件哈希,得到真正的容器索引。hashes 来自 PackReader::hashes。

§Errors

哈希数与文件数不符或条目非法时返回。

Source

pub fn reader(&self) -> PackReader ⓘ

按规划顺序把文件内容串成一条流。

Trait Implementations§

Source§

impl Debug for PackPlan

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.