Extract binary merging logic
This commit is contained in:
parent
7a8cca8fe7
commit
10bc8c7099
9 changed files with 55 additions and 57 deletions
|
|
@ -1,3 +1,5 @@
|
|||
use core::str;
|
||||
|
||||
use base64::{engine::general_purpose::STANDARD_NO_PAD, Engine as _};
|
||||
use errors::SyncLibError;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
|
@ -27,6 +29,20 @@ pub fn base64_to_string(input: &str) -> Result<String, SyncLibError> {
|
|||
String::from_utf8(bytes).map_err(SyncLibError::from)
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn merge(parent: &[u8], left: &[u8], right: &[u8]) -> Result<Vec<u8>, SyncLibError> {
|
||||
Ok(if is_binary(right) {
|
||||
right.to_vec()
|
||||
} else {
|
||||
reconcile::reconcile(
|
||||
str::from_utf8(parent).map_err(SyncLibError::from)?,
|
||||
str::from_utf8(left).map_err(SyncLibError::from)?,
|
||||
str::from_utf8(right).map_err(SyncLibError::from)?,
|
||||
)
|
||||
.into_bytes()
|
||||
})
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn is_binary(data: &[u8]) -> bool { data.iter().any(|&b| b == 0) }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue