Skip to main content

Crate wvb

Crate wvb 

Source
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, checksumFile paths and metadataCompressed 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 tokio
  • source: Bundle source management (builtin/remote)
  • remote: HTTP client for downloading bundles
  • updater: Automatic bundle updates
  • protocol: Custom protocol handlers for serving bundles
  • protocol-proxy: Proxy protocol to local servers
  • integrity: SHA-2 based integrity verification
  • signature: 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.
BundleBuilder
BundleBuilderOptions
BundleDescriptor
Bundle metadata including header and index information.
BundleEntry
BundleReader
BundleWriter
ChecksumReadOptions
ChecksumWriteOptions
DataReadOptions
How entry data is read out of a bundle’s data section.
Header
Bundle header containing format metadata.
HeaderReadOptions
How the header is read out of a bundle.
HeaderReader
HeaderWriter
HeaderWriterOptions
Index
Bundle index mapping file paths to their metadata.
IndexEntry
Metadata for a single file in the bundle.
IndexReadOptions
How the index is read out of a bundle.
IndexReader
IndexWriter
IndexWriterOptions

Enums§

Error
ErrorCode
Version
Version fo Webview Bundle.

Constants§

EXTENSION
MANIFEST_FILENAME
MIME_TYPE

Traits§

Reader
Writer