Struct webc::v1::WebC

source ·
pub struct WebC<'data> {
    pub version: u64,
    pub checksum: Option<Checksum>,
    pub signature: Option<Signature>,
    pub manifest: Manifest,
    pub atoms: Volume<'data>,
    pub volumes: IndexMap<String, Volume<'data>>,
}
Available on crate feature v1 only.
Expand description

Container file, lazily parsed from a set of &'data [u8] bytes

Fields§

§version: u64

Version of the file format

§checksum: Option<Checksum>

Parsed checksum (optional in case of no encoded checksum)

§signature: Option<Signature>

Parsed signature (optional if file was not signed)

§manifest: Manifest

Manifest of the file, see section §2.3.1 of the spec

§atoms: Volume<'data>

Executable files, indexed into one volume (a.wasm => a, b.wasm => b@0.2.1)

§volumes: IndexMap<String, Volume<'data>>

Filesystem volumes: default volume name is atom (containing files of the current package) and user/package@version for external dependencies. Every dependency can be sandboxed to only access its own filesystem volume, not external ones.

Implementations§

source§

impl<'a> WebC<'a>

source

pub fn get_main_args_for_command( &self, command: &str ) -> Result<Vec<String>, String>

source

pub fn get_atom_name_for_command( &self, api: &str, command: &str ) -> Result<String, String>

source

pub fn check_magic_header(data: &[u8]) -> Result<(), Error>

Checks whether the file starts with the header MAGIC

source

pub fn get_volumes_for_package(&self, package: &str) -> Vec<String>

Determines the available volumes for a given package

source

pub fn list_directories(&self, volume: &str) -> Vec<String>

source

pub fn read_dir( &self, package: &str, path: &str ) -> Result<Vec<FsEntry<'a>>, Error>

Returns the directory entries or an error if the directory does not exist

source

pub fn get_file_entry( &self, package: &str, path: &str ) -> Option<(String, OwnedFsEntryFile)>

Looks for the first volume containing “entry”, scoped to the given package

source

pub fn get_check_version(data: &[u8]) -> Result<u64, Error>

Checks whether the version of the file is supported by the parsing implementation

source

pub fn get_checksum_bytes(data: &[u8]) -> Result<&[u8], Error>

Returns the bytes of the checksum

source

pub fn get_manifest_offset_size(data: &[u8]) -> ReadResult<(usize, usize)>

Returns the offset of the manifest start

source

pub fn get_manifest(data: &[u8]) -> Result<Manifest, Error>

source

pub fn get_atoms_volume_offset_size(data: &[u8]) -> ReadResult<(usize, usize)>

Returns the offset of the .atoms section of the file

source

pub fn get_atoms_volume(data: &'a [u8]) -> Result<Volume<'a>, Error>

Parses the .atoms section of the file

source

pub fn get_volume_data_offsets( data: &[u8] ) -> Result<BTreeMap<String, (usize, usize)>, Error>

Returns the offsets of the “volume”

source

pub fn parse_volumes_from_fileblock( data: &'a [u8] ) -> ReadResult<IndexMap<String, Volume<'a>>>

source

pub fn parse_volumes(data: &'a [u8]) -> ReadResult<IndexMap<String, Volume<'a>>>

Parses the .volumes section(s) of the file

source

pub fn compute_checksum(data: &[u8]) -> ReadResult<Option<Checksum>>

Computes the checksum of the file without cloning it

source

pub const fn get_signature_offset_start() -> usize

source

pub fn get_signature_offset_size(data: &[u8]) -> ReadResult<(usize, usize)>

Returns the offset of the signature

source

pub fn get_signature_bytes(data: &[u8]) -> ReadResult<&[u8]>

Read the signature bytes

source

pub fn get_signature(data: &[u8]) -> ReadResult<Option<Signature>>

Returns the (unverified) signature from the file

source

pub fn get_metadata(&self) -> &Manifest

Returns a reference to the manifest

source

pub fn get_package_name(&self) -> String

Returns the current package name with

source

pub fn get_atom(&self, package: &str, atom: &str) -> Result<&[u8], Error>

Returns an atom by name for a given package

source

pub fn get_volume(&self, package: &str, volume: &str) -> Option<&Volume<'a>>

Returns a reference to the filesystem volume of the package

source

pub fn get_file(&self, package: &str, file_path: &str) -> Result<&[u8], Error>

Returns a file for a given package - if you want to use a non-default volume, prefix the file_path with volume://, for example, metadata://README.md

source

pub fn list_volumes(&self, package: &str) -> Vec<String>

Returns a list of volumes for this package

source

pub fn list_packages(&self) -> Vec<PackageInfo>

Returns a list of bundled “package@version” strings contained in this package

source

pub fn list_atoms(&self) -> Vec<String>

Returns the atoms in the root package

source

pub fn get_all_atoms(&self) -> IndexMap<String, &'a [u8]>

Returns a list of all atoms with bytes

source

pub fn list_atoms_for_package(&self, package_orig: &str) -> Vec<String>

List the atoms for a given package

source

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

List the available commands for the root package

source

pub fn parse(data: &'a [u8], options: &ParseOptions) -> ReadResult<Self>

Parses the entire file, depending on the ParseOptions

source

pub fn get_volumes_as_fileblock(&self) -> Vec<u8>

source

pub fn into_bytes(&self, sign_bytes: GenerateChecksum) -> ReadResult<Vec<u8>>

Serialize the .webc file into bytes

Trait Implementations§

source§

impl<'data> Clone for WebC<'data>

source§

fn clone(&self) -> WebC<'data>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<'data> Debug for WebC<'data>

source§

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

Formats the value using the given formatter. Read more
source§

impl<'data> PartialEq for WebC<'data>

source§

fn eq(&self, other: &WebC<'data>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'data> StructuralPartialEq for WebC<'data>

Auto Trait Implementations§

§

impl<'data> Freeze for WebC<'data>

§

impl<'data> RefUnwindSafe for WebC<'data>

§

impl<'data> Send for WebC<'data>

§

impl<'data> Sync for WebC<'data>

§

impl<'data> Unpin for WebC<'data>

§

impl<'data> UnwindSafe for WebC<'data>

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> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

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

§

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

§

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.