Change encoding/decoding
This commit is contained in:
parent
b549bb96b6
commit
9db478bc23
2 changed files with 7 additions and 5 deletions
|
|
@ -10,7 +10,7 @@
|
|||
//! - `errors`: Contains error types used in this crate.
|
||||
use core::str;
|
||||
|
||||
use base64::{engine::general_purpose::STANDARD_NO_PAD, Engine as _};
|
||||
use base64::{engine::general_purpose::STANDARD, Engine as _};
|
||||
use errors::SyncLibError;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
|
|
@ -19,12 +19,12 @@ pub mod errors;
|
|||
/// Encode binary data for easy transport over HTTP. Inverse of
|
||||
/// `base64_to_bytes`.
|
||||
#[wasm_bindgen(js_name = bytesToBase64)]
|
||||
pub fn bytes_to_base64(input: &[u8]) -> String { STANDARD_NO_PAD.encode(input) }
|
||||
pub fn bytes_to_base64(input: &[u8]) -> String { STANDARD.encode(input) }
|
||||
|
||||
/// Inverse of `bytes_to_base64`.
|
||||
#[wasm_bindgen(js_name = base64ToBytes)]
|
||||
pub fn base64_to_bytes(input: &str) -> Result<Vec<u8>, SyncLibError> {
|
||||
STANDARD_NO_PAD.decode(input).map_err(SyncLibError::from)
|
||||
STANDARD.decode(input).map_err(SyncLibError::from)
|
||||
}
|
||||
|
||||
/// Merge two documents with a common parent. Relies on `reconcile::reconcile`
|
||||
|
|
|
|||
|
|
@ -4,16 +4,18 @@ use insta::assert_debug_snapshot;
|
|||
use sync_lib::*;
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
|
||||
|
||||
#[wasm_bindgen_test(unsupported = test)]
|
||||
fn test_bytes_to_base64() {
|
||||
let input = b"hello";
|
||||
let expected = "aGVsbG8";
|
||||
let expected = "aGVsbG8=";
|
||||
assert_eq!(bytes_to_base64(input), expected);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test(unsupported = test)]
|
||||
fn test_base64_to_bytes() {
|
||||
let input = "aGVsbG8";
|
||||
let input = "aGVsbG8=";
|
||||
let expected = b"hello".to_vec();
|
||||
assert_eq!(base64_to_bytes(input).unwrap(), expected);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue