Struct SourceBundleWriter

Source
pub struct SourceBundleWriter<W>
where W: Seek + Write,
{ /* private fields */ }
Expand description

Writer to create SourceBundles.

Writers can either create a new file or be created from an existing file. Then, use add_file to add files and finally call finish to flush the archive to the underlying writer.

Note that dropping the writer

let mut bundle = SourceBundleWriter::create("bundle.zip")?;

// Add file called "foo.txt"
let file = File::open("my_file.txt")?;
bundle.add_file("foo.txt", file, SourceFileInfo::default())?;

// Flush the bundle to disk
bundle.finish()?;

Implementations§

Source§

impl<W> SourceBundleWriter<W>
where W: Seek + Write,

Source

pub fn start(writer: W) -> Result<Self, SourceBundleError>

Creates a bundle writer on the given file.

Source

pub fn is_empty(&self) -> bool

Returns whether the bundle contains any files.

Source

pub fn collect_il2cpp_sources(&mut self, collect_il2cpp: bool)

This controls if source files should be scanned for Il2cpp-specific source annotations, and the referenced C# files should be bundled up as well.

Source

pub fn set_attribute<K, V>(&mut self, key: K, value: V) -> Option<String>
where K: Into<String>, V: Into<String>,

Sets a meta data attribute of the bundle.

Attributes are flushed to the bundle when it is finished. Thus, they can be retrieved or changed at any time before flushing the writer.

If the attribute was set before, the prior value is returned.

Source

pub fn remove_attribute<K>(&mut self, key: K) -> Option<String>
where K: AsRef<str>,

Removes a meta data attribute of the bundle.

If the attribute was set, the last value is returned.

Source

pub fn attribute<K>(&mut self, key: K) -> Option<&str>
where K: AsRef<str>,

Returns the value of a meta data attribute.

Source

pub fn has_file<S>(&self, path: S) -> bool
where S: AsRef<str>,

Determines whether a file at the given path has been added already.

Source

pub fn add_file<S, R>( &mut self, path: S, file: R, info: SourceFileInfo, ) -> Result<(), SourceBundleError>
where S: AsRef<str>, R: Read,

Adds a file and its info to the bundle.

Only files containing valid UTF-8 are accepted.

Multiple files can be added at the same path. For the first duplicate, a counter will be appended to the file name. Any subsequent duplicate increases that counter. For example:

let mut bundle = SourceBundleWriter::create("bundle.zip")?;

// Add file at "foo.txt"
bundle.add_file("foo.txt", File::open("my_duplicate.txt")?, SourceFileInfo::default())?;
assert!(bundle.has_file("foo.txt"));

// Add duplicate at "foo.txt.1"
bundle.add_file("foo.txt", File::open("my_duplicate.txt")?, SourceFileInfo::default())?;
assert!(bundle.has_file("foo.txt.1"));

Returns Ok(true) if the file was successfully added, or Ok(false) if the file aready existed. Otherwise, an error is returned if writing the file fails.

Source

pub fn with_skipped_file_callback( self, callback: impl FnMut(SkippedFileInfo<'_>) + 'static, ) -> Self

Set a callback, which is called for every file that is skipped from being included in the source bundle. The callback receives information about the file being skipped.

Source

pub fn write_object<'data, 'object, O, E>( self, object: &'object O, object_name: &str, ) -> Result<bool, SourceBundleError>
where O: ObjectLike<'data, 'object, Error = E>, E: Error + Send + Sync + 'static,

Writes a single object into the bundle.

Returns Ok(true) if any source files were added to the bundle, or Ok(false) if no sources could be resolved. Otherwise, an error is returned if writing the bundle fails.

This finishes the source bundle and flushes the underlying writer.

Source

pub fn write_object_with_filter<'data, 'object, O, E, F>( self, object: &'object O, object_name: &str, filter: F, ) -> Result<bool, SourceBundleError>
where O: ObjectLike<'data, 'object, Error = E>, E: Error + Send + Sync + 'static, F: FnMut(&FileEntry<'_>, &Option<SourceFileDescriptor<'_>>) -> bool,

Writes a single object into the bundle.

Returns Ok(true) if any source files were added to the bundle, or Ok(false) if no sources could be resolved. Otherwise, an error is returned if writing the bundle fails.

This finishes the source bundle and flushes the underlying writer.

Before a file is written a callback is invoked which can return false to skip a file.

Source

pub fn finish(self) -> Result<(), SourceBundleError>

Writes the manifest to the bundle and flushes the underlying file handle.

Source§

impl SourceBundleWriter<BufWriter<File>>

Source

pub fn create<P>( path: P, ) -> Result<SourceBundleWriter<BufWriter<File>>, SourceBundleError>
where P: AsRef<Path>,

Create a bundle writer that writes its output to the given path.

If the file does not exist at the given path, it is created. If the file does exist, it is overwritten.

Auto Trait Implementations§

§

impl<W> Freeze for SourceBundleWriter<W>
where W: Freeze,

§

impl<W> !RefUnwindSafe for SourceBundleWriter<W>

§

impl<W> !Send for SourceBundleWriter<W>

§

impl<W> !Sync for SourceBundleWriter<W>

§

impl<W> Unpin for SourceBundleWriter<W>
where W: Unpin,

§

impl<W> !UnwindSafe for SourceBundleWriter<W>

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<I, T> ExtractContext<I, ()> for T

Source§

fn extract_context(self, _original_input: I)

Given the context attached to a nom error, and given the original input to the nom parser, extract more the useful context information. 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<I> RecreateContext<I> for I

Source§

fn recreate_context(_original_input: I, tail: I) -> I

Given the original input, as well as the context reported by nom, recreate a context in the original string where the error occurred. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.