[][src]Struct symbolic_debuginfo::sourcebundle::SourceBundleWriter

pub struct SourceBundleWriter<W> where
    W: Seek + Write
{ /* fields omitted */ }

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()?;

Methods

impl<W> SourceBundleWriter<W> where
    W: Seek + Write
[src]

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

Creates a bundle writer on the given file.

pub fn is_empty(&self) -> bool[src]

Returns whether the bundle contains any files.

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

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.

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

Removes a meta data attribute of the bundle.

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

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

Returns the value of a meta data attribute.

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

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

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

Adds a file and its info to the bundle.

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.

pub fn write_object<O>(
    self,
    object: &O,
    object_name: &str
) -> Result<bool, SourceBundleError> where
    O: ObjectLike,
    O::Error: Fail
[src]

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.

pub fn write_object_with_filter<O, F>(
    self,
    object: &O,
    object_name: &str,
    filter: F
) -> Result<bool, SourceBundleError> where
    O: ObjectLike,
    O::Error: Fail,
    F: FnMut(&FileEntry) -> bool
[src]

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.

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

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

impl SourceBundleWriter<BufWriter<File>>[src]

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

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> RefUnwindSafe for SourceBundleWriter<W> where
    W: RefUnwindSafe

impl<W> Send for SourceBundleWriter<W> where
    W: Send

impl<W> Sync for SourceBundleWriter<W> where
    W: Sync

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

impl<W> UnwindSafe for SourceBundleWriter<W> where
    W: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.