Skip to main content

BundleFile

Struct BundleFile 

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

A bundle: header and directory parsed, data decoded on demand.

Implementations§

Source§

impl BundleFile

Source

pub fn open( name: RawStr, data: Bytes, parent: Option<Parent>, meter: &Arc<Meter>, ctx: &Arc<FileContext>, ) -> Result<Arc<Self>, Error>

Reads the header, blocks-info and directory of bytes (the memory reader’s rules). Decodes no data block. Everything it keeps is charged to meter, the input’s.

Source

pub fn open_with_reader( name: RawStr, data: Bytes, parent: Option<Parent>, meter: &Arc<Meter>, ctx: &Arc<FileContext>, reader: ReaderKind, ) -> Result<Arc<Self>, Error>

Self::open by the rules of the reader UnityPy would read data with (ReaderKind::Stream for a top-level file loaded from a path): the header, the blocks-info section and the blocks’ stored bytes are read through it; the blocks-info table and the entries are memory (UnityPy decodes them into bytes, files/BundleFile.py:141-142, :173-186).

Source§

impl BundleFile

Source

pub fn save(&self, options: BundleSaveOptions) -> Result<Bytes, SaveError>

Rebuild the bundle from its live ordered files dictionary. Repeated names collapse to their final row at the first position. Saving retains change flags and leaves the original input intact. None provides canonical idempotence. Original adopts the first loaded block’s codec, so a stored first chunk can change the next Original save’s block layout, as in UnityPy.

Format 9 and named HC follow HEAD 417d595. Earlier formats retain 1.25.2’s other packers. Formats above 9 refuse before output charges. Legacy signatures ignore the packer, as UnityPy does.

Source

pub fn save_with_entries( &self, options: BundleSaveOptions, entries: &[(RawStr, u32, Bytes)], ) -> Result<Bytes, SaveError>

Save an ordered caller-supplied directory of already serialized children. The caller owns and meters the names and payload snapshots.

Source

pub fn save_with_snapshot( &self, options: BundleSaveOptions, entries: &[(RawStr, u32, Bytes)], header: &BundleHeader, block_flags: u16, mode: Option<(u32, u16)>, ) -> Result<Bytes, SaveError>

Save charged caller-owned directory and header snapshots. mode selects the FS/legacy body API; None dispatches from the supplied signature.

Source

pub fn save_fs( &self, data_flag: u32, block_info_flag: u16, options: SaveOptions, ) -> Result<Bytes, SaveError>

Save the FS layout, with header/blocks-info flags first and data block flags second. Encryption is removed, never emitted: exactly the encryption mask’s bits and each block’s 0x100 bit are cleared. This Tier C correction applies in both layout modes.

Source

pub fn save_fs_with_entries( &self, data_flag: u32, block_info_flag: u16, options: SaveOptions, entries: &[(RawStr, u32, Bytes)], ) -> Result<Bytes, SaveError>

Save the FS body using an ordered supplied child directory.

Source§

impl BundleFile

Source

pub fn save_web_raw(&self, options: SaveOptions) -> Result<Bytes, SaveError>

Save UnityRaw or UnityWeb’s legacy layout, with one level and a directory padded to four bytes. UnityWeb uses a size-prefixed raw LZMA1 stream. Format 6 belongs to save_fs instead.

Source

pub fn save_web_raw_with_entries( &self, options: SaveOptions, entries: &[(RawStr, u32, Bytes)], ) -> Result<Bytes, SaveError>

Save legacy layout using caller-owned, metered serialized child snapshots.

Source

pub fn save_web_raw_with_snapshot( &self, options: SaveOptions, entries: &[(RawStr, u32, Bytes)], header: &BundleHeader, ) -> Result<Bytes, SaveError>

Save a charged legacy directory and current caller-owned header.

Source§

impl BundleFile

Source

pub fn constructor_position(&self) -> i128

Final cursor of the constructor’s outer input reader.

Source

pub fn meter(&self) -> &Arc<Meter> ⓘ

The meter of the input it belongs to (of this open of it); its entries, nested bundles included, charge it too.

Source

pub fn source(&self) -> &Bytes

The input bytes it was opened on (for telling two handles on one input apart from two inputs: a resource read through from’s own handle, plan section 3.13).

Source

pub fn name(&self) -> &RawStr

The name it was opened under.

Source

pub fn header(&self) -> &BundleHeader

The header.

Source

pub fn blocks(&self) -> &[BlockInfo]

The blocks, in file order (Fs layout).

Source

pub fn directory(&self) -> &[DirEntry]

The directory, in file order, repeated paths kept.

Source

pub fn files(&self) -> &[FileSlot]

Loaded files dict, in order. Newly created resource writers are in Self::writeable_cabs and follow these entries when saved.

Source

pub fn parent(&self) -> Option<&Parent>

The container this bundle is an entry of.

Source

pub fn context(&self) -> &Arc<FileContext> ⓘ

The context it was opened with.

Source

pub fn uncompressed_size(&self) -> u64

The sum of the blocks’ declared decoded sizes: what a full decode is expected to cost. The actual total can differ (module docs).

Source

pub fn counts(&self) -> BundleCounts

What this bundle’s block reads have decoded, dropped, decoded again and cached so far (BundleCounts; a nested bundle counts its own): what plan section 8’s R2 and R3 measure. Takes the run index’s lock for the runs’ share.

Source

pub fn entry_bytes(&self, dir_index: usize) -> Result<Bytes, Error>

Directory entry dir_index’s bytes: the Python slice data[offset : offset + size] of the joined data (size -1 to the end, negative indexes from the end, short at the end). Measures every block before the slice first (module docs).

Source

pub fn pinned(&self) -> u64

The length of the buffer this bundle’s own bytes are a slice of, which a slice of a stored block keeps alive (Parent::pinned; its own length for a top-level bundle).

Source

pub fn entry_range( &self, dir_index: usize, range: Range<u64>, ) -> Result<Bytes, Error>

A byte range of an entry (a .resS read), short at the end of the entry as a Python slice. It measures every block before the range as any read does, slices a cached run that covers the range’s blocks, and otherwise decodes those blocks into a run it caches, so later ranges in the same blocks are slices of it.

Source

pub fn entry(&self, dir_index: usize) -> Result<File, Error>

Directory entry dir_index, detected and parsed (parse_file) and published once (crate::once::get_or_publish_result); under contention two callers may both parse it, and the loser’s result (and its charge) is dropped. A parse the meter or the budget refuses is returned and not kept.

Source

pub fn load_all(&self) -> Result<(), Error>

UnityPy’s eager load (File.read_files, File.py:76-90): every block decoded, every directory entry parsed in order (a path repeated in the directory included: its earlier entry can fail the bundle though the files dict keeps the later one); the first failure fails the bundle.

Source§

impl BundleFile

Source

pub fn get_writeable_cab( &self, name: Option<&RawStr>, ) -> Result<WriteableCab, SaveError>

Create or reuse a resource writer. Existing reader keys refuse. Creation alone neither marks changed nor registers an environment CAB.

Source

pub fn writeable_cabs(&self) -> Result<MeteredVec<WriteableCab>, SaveError>

The writers added after the loaded files, in dictionary order.

Source§

impl BundleFile

Source

pub fn mark_changed(&self)

Mark this container and all its live parent containers changed.

Source

pub fn is_changed(&self) -> bool

Whether this container or one of its children was marked changed.

Trait Implementations§

Source§

impl Debug for BundleFile

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for BundleFile

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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.