Skip to main content

MdzArchive

Struct MdzArchive 

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

An opened, read-only .mdz archive.

The archive bytes are kept in memory; nothing is extracted to disk. Opening is safe for untrusted input: see MdzArchive::open.

Implementations§

Source§

impl MdzArchive

Source

pub fn open(data: impl Into<Vec<u8>>) -> Result<Self>

Open an archive from its bytes, with the default Limits.

Fails, with a stable ErrorCode, for:

Symbolic link entries are never followed or read: they’re listed in special_files, with a warning.

Source

pub fn open_with_limits( data: impl Into<Vec<u8>>, limits: Limits, ) -> Result<Self>

Open an archive from its bytes with custom limits.

Source

pub fn open_path(path: impl AsRef<Path>) -> Result<Self>

Read and open the archive at path.

Source

pub fn open_path_with_limits( path: impl AsRef<Path>, limits: Limits, ) -> Result<Self>

Read and open the archive at path with custom limits.

Source

pub fn as_bytes(&self) -> &[u8] ⓘ

The archive bytes.

Source

pub fn into_bytes(self) -> Vec<u8> ⓘ

The archive bytes, consuming the archive.

Source

pub fn path(&self) -> Option<&Path>

The file the archive was opened from, if any.

Source

pub fn limits(&self) -> &Limits

The limits the archive was opened with.

Source

pub fn files(&self) -> impl ExactSizeIterator<Item = &str> + '_

File entry paths, as stored, in archive order. Directory entries and symbolic links aren’t included.

Source

pub fn directories(&self) -> impl ExactSizeIterator<Item = &str> + '_

Directory entries the archive stores, such as an empty folder (each ends in /). A folder only implied by a file path like docs/a.md isn’t listed.

Source

pub fn special_files(&self) -> impl ExactSizeIterator<Item = &str> + '_

Symbolic link entries, as stored. Never followed or read (Section 13.1).

Source

pub fn documents(&self) -> Vec<&str>

Markdown file entries, sorted.

Source

pub fn find(&self, path: &str) -> Option<&str>

The stored file path matching path (NFC, case-sensitive; Section 5.4.1).

Source

pub fn contains(&self, path: &str) -> bool

Whether a file matching path exists (Section 5.4.1).

Source

pub fn find_directory(&self, path: &str) -> Option<&str>

The stored directory entry matching path, with or without its trailing /.

Source

pub fn entry_info(&self, path: &str) -> Option<EntryInfo>

ZIP metadata of the file matching path.

Source

pub fn read_bytes(&self, path: &str) -> Result<Vec<u8>>

A file’s bytes. Fails with ErrorCode::NotFound if there’s no such file, ErrorCode::ZipInvalid if its data is corrupt, and ErrorCode::LimitExceeded if it decompresses past its declared size or the limits.

Source

pub fn read_text(&self, path: &str) -> Result<String>

A file’s text, decoded as UTF-8 (Section 7.1), with a leading BOM removed. Line endings are left as written. Fails with ErrorCode::TextInvalid if the file isn’t UTF-8.

Source

pub fn entry_point(&self) -> Result<String>

The primary Markdown file (Section 5.5). Fails with ErrorCode::EntryPointInvalid or ErrorCode::EntryPointMissing for a bad manifest entryPoint (never a silent fallback), or ErrorCode::EntryPointUnresolved.

Source

pub fn manifest(&self) -> Option<&Manifest>

The parsed manifest.json, with every field kept, or None.

Source

pub fn mode(&self) -> Mode

document or project (Section 5.7).

Source

pub fn title(&self) -> Option<&str>

The manifest title, if it’s a non-empty string.

Source

pub fn ignored_fields(&self) -> &[&'static str]

Descriptive manifest fields with a wrong type or value, which are ignored (Section 6.4).

Source

pub fn warnings(&self) -> &[Diagnostic]

Warnings from opening the archive: symbolic links, repeated manifest members, ignored manifest fields.

Resolve link written in document of this archive (Sections 9.3–9.6).

Opened from a file, links may reach files in the archive’s own directory and below it, and into archives there. Opened from bytes, links that leave the archive are unresolved (UnresolvedReason::NoHostLocation). For other hosts, use resolve_link with a LinkHost.

Source

pub fn validate(&self) -> Vec<Diagnostic>

Conformance findings for this archive. Never fails.

Opening already rejects what makes an archive unreadable; this adds the entry point, producer-manifest and cover checks to the warnings from opening.

Source§

impl MdzArchive

Source

pub fn update(&self, changes: &Update) -> Result<Vec<u8>>

Apply changes and return the new archive bytes (Section 14.1). The archive itself isn’t changed.

  • Entries not written or removed are copied as stored: same bytes, compression, timestamp and attributes. Each is checked (CRC-32, limits) before it’s copied.
  • Directory entries, such as empty folders, are kept.
  • Symbolic links are kept unless removed by name or with Update::drop_special_files; the archive then stays non-conforming and the warning still applies. Writing a file at the same path replaces the link.
  • The manifest keeps every field, including unknown ones; it’s added if missing, with the entry point the archive resolved to before.
  • The entry point must resolve to the same file afterwards unless Update::entry_point names a new one; otherwise ErrorCode::EntryPointChanged.

Trait Implementations§

Source§

impl Clone for MdzArchive

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MdzArchive

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.