pub struct SourceBundleWriter<W>{ /* 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>
impl<W> SourceBundleWriter<W>
Sourcepub fn start(writer: W) -> Result<Self, SourceBundleError>
pub fn start(writer: W) -> Result<Self, SourceBundleError>
Creates a bundle writer on the given file.
Sourcepub fn collect_il2cpp_sources(&mut self, collect_il2cpp: bool)
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.
Sourcepub fn set_attribute<K, V>(&mut self, key: K, value: V) -> Option<String>
pub fn set_attribute<K, V>(&mut self, key: K, value: V) -> Option<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.
Sourcepub fn remove_attribute<K>(&mut self, key: K) -> Option<String>
pub fn remove_attribute<K>(&mut self, key: K) -> Option<String>
Removes a meta data attribute of the bundle.
If the attribute was set, the last value is returned.
Sourcepub fn attribute<K>(&mut self, key: K) -> Option<&str>
pub fn attribute<K>(&mut self, key: K) -> Option<&str>
Returns the value of a meta data attribute.
Sourcepub fn has_file<S>(&self, path: S) -> bool
pub fn has_file<S>(&self, path: S) -> bool
Determines whether a file at the given path has been added already.
Sourcepub fn add_file<S, R>(
&mut self,
path: S,
file: R,
info: SourceFileInfo,
) -> Result<(), SourceBundleError>
pub fn add_file<S, R>( &mut self, path: S, file: R, info: SourceFileInfo, ) -> Result<(), SourceBundleError>
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.
Sourcepub fn with_skipped_file_callback(
self,
callback: impl FnMut(SkippedFileInfo<'_>) + 'static,
) -> Self
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.
Sourcepub fn write_object<'data, 'object, O, E>(
self,
object: &'object O,
object_name: &str,
) -> Result<bool, SourceBundleError>
pub fn write_object<'data, 'object, O, E>( self, object: &'object O, object_name: &str, ) -> Result<bool, SourceBundleError>
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.
Sourcepub 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,
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.
Sourcepub fn finish(self) -> Result<(), SourceBundleError>
pub fn finish(self) -> Result<(), SourceBundleError>
Writes the manifest to the bundle and flushes the underlying file handle.
Source§impl SourceBundleWriter<BufWriter<File>>
impl SourceBundleWriter<BufWriter<File>>
Sourcepub fn create<P>(
path: P,
) -> Result<SourceBundleWriter<BufWriter<File>>, SourceBundleError>
pub fn create<P>( path: P, ) -> Result<SourceBundleWriter<BufWriter<File>>, SourceBundleError>
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.