Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helper to copy Vec<u8> to Uint8Array #37

Closed
kylebarron opened this issue Mar 14, 2022 · 0 comments · Fixed by #38
Closed

Helper to copy Vec<u8> to Uint8Array #37

kylebarron opened this issue Mar 14, 2022 · 0 comments · Fixed by #38

Comments

@kylebarron
Copy link
Owner

I.e. each public binding should be able to change from

pub fn read_parquet(parquet_file: &[u8]) -> Result<Uint8Array, JsValue> {
let buffer = match crate::arrow1::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);
}

to

pub fn read_parquet(parquet_file: &[u8]) -> Result<Uint8Array, JsValue> {
    let buffer = crate::arrow1::reader::read_parquet(parquet_file)?;
    Ok(crate::utils::copy_vec_to_uint8array(buffer))
}

Should be some way to make the ? work in this context? You might need to add an impl for converting from the ParquetError to a js Error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant