baste64

Crates.iobaste64
lib.rsbaste64
version
sourcesrc
created_at2024-11-22 18:15:49.081301
updated_at2024-11-22 18:15:49.081301
descriptionA base64 codec
homepage
repository
max_upload_size
id1457590
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Matthew Kim (friendlymatthew)

documentation

README

based64

A base64 codec using wasm32 SIMD intrinsics.

use based64::{decode, encode};
use wasm_bindgen::{wasm_bindgen, JsValue};

#[wasm_bindgen]
fn main() -> Result<(), JsValue> {
  let ascii = b"VGhlIGRvZyBsaWNrZWQgdGhlIG9pbCwgYW5kIGV2ZXJ5Ym9keSBsYXVnaGVkLg==";
  let message = decode(ascii)?; // The dog licked the oil, and everybody laughed.

  let encoded_to_ascii = encode(&message)?;
  assert_eq!(encoded_to_ascii, ascii.to_vec());

  Ok(())
}

or

import init, {
    encode,
    decode,
} from "./pkg/based64.js";

async function run(): boolean {
    await init();
    
    let data = "howdy";
    let bytes = new TextEncoder().encode(data);
    let ascii: Uint8Array = encode(bytes);
    let rawString = decode(ascii);
    
    return data === rawString;
}

Requirements

# make sure to have the wasm32 target installed
rustup target add wasm32-unknown-unknown

RUSTFLAGS=\"-C target-feature=+simd128 cargo test --target=wasm32-unknown-unknown

Benchmarks

To run benchmarks, run just bench. It should lead you to a web page, you can view the console.

The benchmark rules are very simple, it must follow window.btoa and window.atob's function header: String -> String. Since certain functions have different function signatures, the work needed to convert into a String is included in the measurement.

Codecs measured:

  • base64 with wasm_bindgen bindings
  • window.atob(), window.btoa()
  • based64 Uint8Array -> Uint8Array with wasm_bindgen bindings
  • based64 String -> String with wasm_bindgen bindings

Resources

Commit count: 0

cargo fmt