Struct Archive

Source
pub struct Archive<'conn> { /* private fields */ }
Expand description

A SQLite archive.

This is the main type for reading and writing to the archive. You can only access an Archive within the context of a transaction, which you’ll typically use Connection::exec for.

A SQLite archive is a SQLite database with a table named sqlar that conforms to a specific schema. A SQLite archive may contain other tables, and this library will ignore them.

All file paths in a SQLite archive are relative paths; trying to use an absolute path will result in an error.

All file paths in a SQLite archive are encoded using the database encoding; trying to use a path that is not valid Unicode will result in an error.

Implementations§

Source§

impl<'conn> Archive<'conn>

Source

pub fn open<'ar, P: AsRef<Path>>( &'ar mut self, path: P, ) -> Result<File<'conn, 'ar>>

Create a handle to the file at the given path.

This doesn’t guarantee that the file actually exists in the archive; it only returns a handle to a file that may or may not exist.

See File::exists to check if the file actually exists in the archive.

Source

pub fn list(&mut self) -> Result<ListEntries<'_>>

Return an iterator over the files in this archive.

This is the same as Archive::list_with, but using the default options.

Source

pub fn list_with(&mut self, opts: &ListOptions) -> Result<ListEntries<'_>>

Return an iterator over the files in this archive.

This accepts a ListOptions to sort and filter the results.

This returns an error if mutually exclusive options were specified together in ListOptions.

§Examples

List the regular files that are descendants of parent/dir in descending order by size.

let opts = ListOptions::new().by_size().desc().descendants_of("parent/dir");

for result in archive.list_with(&opts)? {
    let entry = result?;
    let path = entry.path();

    if let FileMetadata::File { size, .. } = entry.metadata() {
        println!("{}: {}", path.to_string_lossy(), size);
    }
}
Source

pub fn archive<P: AsRef<Path>, Q: AsRef<Path>>( &mut self, from: P, to: Q, ) -> Result<()>

Copy the filesystem directory tree at from into the archive at to.

This is the same as Archive::archive_with, but using the default options.

Source

pub fn archive_with<P: AsRef<Path>, Q: AsRef<Path>>( &mut self, from: P, to: Q, opts: &ArchiveOptions, ) -> Result<()>

Copy the directory tree at in the filesystem at from into the archive at to.

The file at from may be either a directory or a regular file.

§Errors
Source

pub fn extract<P: AsRef<Path>, Q: AsRef<Path>>( &mut self, from: P, to: Q, ) -> Result<()>

Copy the directory tree in the archive at from into the filesystem at to.

This is the same as Archive::extract_with, but using the default options.

Source

pub fn extract_with<P: AsRef<Path>, Q: AsRef<Path>>( &mut self, from: P, to: Q, opts: &ExtractOptions, ) -> Result<()>

Copy the directory tree in the archive at from into the filesystem at to.

The file at from may be either a directory or a regular file.

§Errors
Source

pub fn umask(&self) -> FileMode

The current umask for newly created files and directories.

Source

pub fn set_umask(&mut self, mode: FileMode)

Set the umask for newly created files and directories.

This specifies the mode bits that will not be set, assuming the default mode for regular files is 666 and the default mode for directories is 777.

The default umask is FileMode::OTHER_W (002).

§Examples
archive.set_umask(FileMode::OTHER_R | FileMode::OTHER_W);
assert_eq!(archive.umask(), FileMode::OTHER_R | FileMode::OTHER_W);

Trait Implementations§

Source§

impl<'conn> Debug for Archive<'conn>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'conn> Freeze for Archive<'conn>

§

impl<'conn> !RefUnwindSafe for Archive<'conn>

§

impl<'conn> !Send for Archive<'conn>

§

impl<'conn> !Sync for Archive<'conn>

§

impl<'conn> Unpin for Archive<'conn>

§

impl<'conn> !UnwindSafe for Archive<'conn>

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, 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.