1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//! A library for reading and writing WEBC files.
//!
//! The [`Container`] provides an abstraction over the various WEBC versions
//! this crate can handle. As such, it tries to cater to the lowest common
//! denominator and favors portability over performance or power.
//!
//! In general, errors that occur during lazy operations won't be accessible to
//! the user.
//!
//! If more flexibility is required, consider using [`crate::detect()`] and
//! instantiating a compatible parser directly.
//!
//! ```rust,no_run
//! use webc::{
//!     Container,
//!     Version,
//!     v2::read::OwnedReader,
//!     v1::{ParseOptions, WebC},
//! };
//! let bytes: &[u8] = b"...";
//!
//! match webc::detect(bytes) {
//!     Ok(Version::V1) => {
//!         let options = ParseOptions::default();
//!         let webc = WebC::parse(bytes, &options).unwrap();
//!         if let Some(signature) = webc.signature {
//!             println!("Package signature: {:?}", signature);
//!         }
//!     }
//!     Ok(Version::V2) => {
//!         let webc = OwnedReader::parse(bytes).unwrap();
//!         let index = webc.index();
//!         let signature = &index.signature;
//!         if !signature.is_none() {
//!             println!("Package signature: {signature:?}");
//!         }
//!     }
//!     Ok(other) => todo!("Unsupported version, {other}"),
//!     Err(e) => todo!("An error occurred: {e}"),
//! }
//! ```

#![warn(unreachable_pub, elided_lifetimes_in_paths)]
#![deny(missing_docs, missing_debug_implementations)]

pub extern crate bytes;
pub extern crate indexmap;

#[cfg(test)]
#[macro_use]
extern crate pretty_assertions;

#[cfg(test)]
#[macro_use]
mod macros;

mod container;
mod detect;
pub mod metadata;
mod path_segments;
mod readable_bytes;
mod utils;
#[allow(missing_docs)]
pub mod v1;
pub mod v2;
mod version;
mod volume;
#[cfg(feature = "package")]
pub mod wasmer_package;

/// The type for [`MAGIC`].
pub type Magic = [u8; 5];

/// File identification bytes stored at the beginning of the file.
pub const MAGIC: Magic = *b"\0webc";

pub use crate::{
    container::Container,
    detect::{detect, is_webc, DetectError},
    path_segments::{PathSegment, PathSegmentError, PathSegments, ToPathSegments},
    version::Version,
    volume::{Metadata, Volume, VolumeError},
};

/// A compatibility layer for dealing with different versions of the WEBC binary
/// format.
#[deprecated(since = "5.1.0", note = "Import types directly from the crate")]
pub mod compat {
    pub use crate::{
        container::{Container, ContainerError},
        volume::{Metadata, Volume, VolumeError},
    };

    #[deprecated = "Use shared_buffer::OwnedBuffer directly"]
    pub use shared_buffer::OwnedBuffer as SharedBytes;
}