Skip to main content

create

Function create 

Source
pub fn create<P, C>(
    files: impl IntoIterator<Item = (P, C)>,
    options: &CreateOptions,
) -> Result<Vec<u8>>
where P: AsRef<str>, C: AsRef<[u8]>,
Expand description

Build a new .mdz archive and return its bytes.

files are archive paths and their content, written in order. The archive always gets a manifest.json (Section 14.1) with spec, producer, title, mode, entryPoint, created and modified; fields from CreateOptions::manifest are kept. A manifest.json among files is used as the starting manifest when none is given.

Paths are written in NFC with the UTF-8 flag. Fails for an invalid or duplicate path, a file that’s also a directory, an entry point that’s invalid, missing or ambiguous, or an unknown mode.

let data = mdzip_core::create(
    [("index.md", "# Hello\n\n![logo](images/logo.png)\n".as_bytes()), ("images/logo.png", b"\x89PNG")],
    &mdzip_core::CreateOptions::new(),
)?;
let archive = mdzip_core::MdzArchive::open(data)?;
assert_eq!(archive.entry_point()?, "index.md");
assert_eq!(archive.title(), Some("Hello"));