Expand description
§Webview Bundle Core
An offline-first web resources delivery system for webview-mounted frameworks and platforms (e.g., Electron, Tauri, with Android and iOS planned).
§Overview
Webview Bundle provides a compressed, verified bundle format (.wvb) for delivering web
resources to webview applications. It supports:
- Offline-first architecture: Bundle resources locally for immediate availability
- Delta updates: Download only what changed between versions
- Integrity verification: Ensure bundle authenticity with checksums and signatures
- Source management: Organize bundles with builtin and remote sources
- HTTP protocol support: Serve bundles through custom protocol handlers
§Bundle Format
The .wvb format consists of three main parts:
| Header (17 bytes) | Index (variable) | Data (variable) |
|---|---|---|
| Magic number, version, index size, checksum | File paths and metadata | Compressed file contents |
- Header: Magic number (🌐🎁), format version, index size, and checksum
- Index: HashMap of file paths to offset/length/headers, with checksum
- Data: LZ4-compressed file contents with xxHash-32 checksums
§Quick Start
use wvb::{Bundle, BundleBuilder, BundleEntry};
// Create a new bundle
let mut builder = BundleBuilder::new();
builder.insert_entry(
"/index.html",
BundleEntry::new(b"<html>...</html>", "text/html", None),
);
builder.insert_entry(
"/app.js",
BundleEntry::new(b"console.log('hello');", "text/javascript", None),
);
let bundle = builder.build().unwrap();
// Write to file
let mut file = File::create("app.wvb").await.unwrap();
AsyncBundleWriter::new(&mut file).write(&bundle).await.unwrap();
// Read from file
let mut file = File::open("app.wvb").await.unwrap();
let mut reader = AsyncBundleReader::new(&mut file);
// `AsyncBundleReader` reads either a `Bundle` or a `BundleDescriptor`, and the future
// it returns is opaque — so the one you want is named on the call.
let bundle = AsyncReader::<Bundle>::read(&mut reader).await.unwrap();
// Access files
let html = bundle.get_data("/index.html").unwrap().unwrap();§Features
async: Async I/O support with tokiosource: Bundle source management (builtin/remote)remote: HTTP client for downloading bundlesupdater: Automatic bundle updatesprotocol: Custom protocol handlers for serving bundlesprotocol-proxy: Proxy protocol to local serversintegrity: SHA-2 based integrity verificationsignature: Digital signature verification (ECDSA, Ed25519, RSA)full: Enable all features
§Bundle Source
Organize multiple bundle versions with the BundleSource API:
use wvb::source::BundleSource;
let source = BundleSource::builder()
.builtin_dir("./builtin") // Shipped with app
.remote_dir("./remote") // Downloaded updates
.build();
// Load current version (remote takes priority)
let bundle = source.fetch_bundle("app").await.unwrap();§Remote Updates
Download and verify bundles from a remote server:
use wvb::remote::Remote;
use wvb::source::{BundleManifestMetadata, BundleSource};
let remote = Remote::builder()
.endpoint("https://updates.example.com")
.build()
.unwrap();
let source = BundleSource::builder()
.remote_dir("./remote")
.build();
// Download the current version, then write the bytes exactly as received: the
// integrity string covers those bytes, so storing them verbatim keeps the file
// verifiable on every later load.
let (info, _bundle, data) = remote.download("app", None).await.unwrap();
source
.write_remote_bundle_data(
"app",
&info.version,
&data,
BundleManifestMetadata {
etag: info.etag,
integrity: info.integrity,
signature: info.signature,
last_modified: info.last_modified,
},
)
.await
.unwrap();
source.update_remote_version("app", &info.version).await.unwrap();Re-exports§
pub use http;
Structs§
- Bundle
- A complete bundle including metadata and file data.
- Bundle
Builder - Bundle
Builder Options - Bundle
Descriptor - Bundle metadata including header and index information.
- Bundle
Entry - Bundle
Reader - Bundle
Writer - Checksum
Read Options - Checksum
Write Options - Data
Read Options - How entry data is read out of a bundle’s data section.
- Header
- Bundle header containing format metadata.
- Header
Read Options - How the header is read out of a bundle.
- Header
Reader - Header
Writer - Header
Writer Options - Index
- Bundle index mapping file paths to their metadata.
- Index
Entry - Metadata for a single file in the bundle.
- Index
Read Options - How the index is read out of a bundle.
- Index
Reader - Index
Writer - Index
Writer Options