-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Helper to copy vec<u8> to Uint8Array (#38)
- Loading branch information
1 parent
bfd6943
commit dfe80d2
Showing
3 changed files
with
30 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,19 @@ | ||
use crate::utils::copy_vec_to_uint8_array; | ||
use js_sys::Uint8Array; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen(js_name = readParquet2)] | ||
pub fn read_parquet2(parquet_file: &[u8]) -> Result<Uint8Array, JsValue> { | ||
let buffer = match crate::arrow2::reader::read_parquet(parquet_file) { | ||
// This function would return a rust vec that would be copied to a Uint8Array here | ||
Ok(buffer) => buffer, | ||
Err(error) => return Err(JsValue::from_str(format!("{}", error).as_str())), | ||
}; | ||
|
||
let return_len = match (buffer.len() as usize).try_into() { | ||
Ok(return_len) => return_len, | ||
Err(error) => return Err(JsValue::from_str(format!("{}", error).as_str())), | ||
}; | ||
let return_vec = Uint8Array::new_with_length(return_len); | ||
return_vec.copy_from(&buffer); | ||
return Ok(return_vec); | ||
match crate::arrow2::reader::read_parquet(parquet_file) { | ||
Ok(buffer) => copy_vec_to_uint8_array(buffer), | ||
Err(error) => Err(JsValue::from_str(format!("{}", error).as_str())), | ||
} | ||
} | ||
|
||
#[wasm_bindgen(js_name = writeParquet2)] | ||
pub fn write_parquet2(arrow_file: &[u8]) -> Result<Uint8Array, JsValue> { | ||
let buffer = match crate::arrow2::writer::write_parquet(arrow_file) { | ||
// This function would return a rust vec that would be copied to a Uint8Array here | ||
Ok(buffer) => buffer, | ||
Err(error) => return Err(JsValue::from_str(format!("{}", error).as_str())), | ||
}; | ||
|
||
let return_len = match (buffer.len() as usize).try_into() { | ||
Ok(return_len) => return_len, | ||
Err(error) => return Err(JsValue::from_str(format!("{}", error).as_str())), | ||
}; | ||
let return_vec = Uint8Array::new_with_length(return_len); | ||
return_vec.copy_from(&buffer); | ||
return Ok(return_vec); | ||
match crate::arrow2::writer::write_parquet(arrow_file) { | ||
Ok(buffer) => copy_vec_to_uint8_array(buffer), | ||
Err(error) => Err(JsValue::from_str(format!("{}", error).as_str())), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters