Skip to content

Commit

Permalink
update b64 for cran
Browse files Browse the repository at this point in the history
  • Loading branch information
JosiahParry committed Jul 1, 2024
1 parent eeedef7 commit 942a493
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: b64
Title: Fast and Vectorized Base 64 Engine
Version: 0.1.0.9000
Version: 0.1.1
Authors@R: c(
person("Josiah", "Parry", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-9910-865X")),
Expand Down
12 changes: 6 additions & 6 deletions src/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ version = '0.1.0'
edition = '2021'

[lib]
crate-type = [ 'staticlib' ]
crate-type = ['staticlib']
name = 'b64'

[dependencies]
base64 = "0.21.7"
extendr-api = {version = "*", features = ["either"]}
extendr-api = { version = "0.7.0", features = ["either"] }
itertools = "0.12.0"
23 changes: 13 additions & 10 deletions src/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use extendr_api::prelude::*;
use itertools::{Either, Itertools};
use std::io::Read;

#[extendr(use_try_from = true)]
#[extendr]
fn encode_(what: Either<String, Raw>, engine: Robj) -> String {
let eng: ExternalPtr<GeneralPurpose> = engine.try_into().unwrap();
match what {
Expand All @@ -18,7 +18,7 @@ fn encode_(what: Either<String, Raw>, engine: Robj) -> String {
}
}

#[extendr(use_try_from = true)]
#[extendr]
fn encode_vectorized_(what: Either<Strings, List>, engine: Robj) -> Strings {
let eng: ExternalPtr<GeneralPurpose> = engine.try_into().unwrap();
match what {
Expand Down Expand Up @@ -84,7 +84,7 @@ fn encode_file_(path: &str, engine: Robj) -> String {
/// @param encoded a character vector of base64 encoded strings.
/// @export
/// @rdname utils
#[extendr(use_try_from = true)]
#[extendr]
fn b64_chunk(encoded: Strings, width: Either<i32, f64>) -> List {
let width = match width {
Left(l) => l,
Expand Down Expand Up @@ -114,7 +114,7 @@ fn b64_chunk(encoded: Strings, width: Either<i32, f64>) -> List {
/// @param newline a character scalar defining the newline character.
/// @export
/// @rdname utils
#[extendr(use_try_from = true)]
#[extendr]
fn b64_wrap(chunks: Either<List, Strings>, newline: &str) -> Strings {
match chunks {
Left(l) => l
Expand All @@ -136,8 +136,8 @@ fn b64_wrap_(chunks: Strings, newline: &str) -> String {
chunks.into_iter().join(newline)
}

#[extendr(use_try_from = true)]
fn decode_(input: Either<String, Raw>, engine: Robj) -> Robj {
#[extendr]
fn decode_(input: Either<String, Raw>, engine: Robj) -> List {
let eng: ExternalPtr<GeneralPurpose> = engine.try_into().unwrap();
let res = match input {
Either::Left(s) => {
Expand All @@ -156,10 +156,11 @@ fn decode_(input: Either<String, Raw>, engine: Robj) -> Robj {
list!(Raw::from_bytes(&res))
.set_class(&["blob", "vctrs_list_of", "vctrs_vctr", "list"])
.unwrap()
.clone()
}

#[extendr(use_try_from = true)]
fn decode_vectorized_(what: Either<Strings, List>, engine: Robj) -> Robj {
#[extendr]
fn decode_vectorized_(what: Either<Strings, List>, engine: Robj) -> List {
let eng: ExternalPtr<GeneralPurpose> = engine.try_into().unwrap();
match what {
Either::Left(s) => s
Expand All @@ -181,7 +182,8 @@ fn decode_vectorized_(what: Either<Strings, List>, engine: Robj) -> Robj {
})
.collect::<List>()
.set_class(&["blob", "vctrs_list_of", "vctrs_vctr", "list"])
.unwrap(),
.unwrap()
.clone(),
Either::Right(r) => r
.into_iter()
.map(|(_, b)| {
Expand All @@ -199,7 +201,8 @@ fn decode_vectorized_(what: Either<Strings, List>, engine: Robj) -> Robj {
})
.collect::<List>()
.set_class(&["blob", "vctrs_list_of", "vctrs_vctr", "list"])
.unwrap(),
.unwrap()
.clone(),
}
}

Expand Down
Binary file modified src/rust/vendor.tar.xz
Binary file not shown.

0 comments on commit 942a493

Please sign in to comment.