kv-assets & kv-sync

Store static assets in Workers KV for Rust-WASM Worker HTTP servers

The command-line program kv-sync, is a build tool that syncs files between a local folder and Workers KV, and generates a small manifest that is published with the worker wasm.

This crate was originally developed to support StaticFileHandler from wasm-service, to add static file support for Rust Worker-based http servers.

Although wrangler does a similar kind of sync for projects configured as a Workers "Site", (and we do reuse a lot of code from wrangler in this implementation), there are a few differences:

Installation

To install kv-sync, cargo install kv-assets, and the program kv-sync will be added to .cargo/bin.

If you want to include the kv-assets library in your project, add a line to Cargo.toml:

`kv-assets = "0.2"`

kv-sync operations

kv-sync does the following:

Adding kv-sync to dev workflow

Run kv-sync at least once before publishing the worker the first time. This will upload the files and generate the manifest.

It is not necessary to run kv-sync again until there is a change to assets (anything in the public folder). If a file in that folder changes, run the following:

```sh kv-sync wrangler publish

if wrangler publish succeeded without errors, then also run

kv-sync --prune ```

The first kv-sync regnerates the manifest and uploads modified files; and wrangler publish publishes the code with the updated manifest. if publish succeeds, it is safe to run the prune step to remove old assets in KV storage.