b64

A lightweight and very fast base64 encoder and decoder.

https://github.com/extendr/b64

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (16.0%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

A lightweight and very fast base64 encoder and decoder.

Basic Info
Statistics
  • Stars: 21
  • Watchers: 5
  • Forks: 4
  • Open Issues: 1
  • Releases: 0
Created over 2 years ago · Last pushed 12 months ago
Metadata Files
Readme Changelog License

README.Rmd

---
output: github_document
---



```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```

# b64 


[![R-CMD-check](https://github.com/extendr/b64/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/extendr/b64/actions/workflows/R-CMD-check.yaml)


b64 is a dependency free, fast, lightweight, and vectorized base64 encoder and decoder.

## Installation

You can install b64 from CRAN with

```r
install.packages("b64")
```

## Example

Encode to base64 using `encode()`.

```{r example}
library(b64)

hello <- encode("Hello, from extendr")
hello
```

Decode using `decode()`. Note that the returned object will always have the `"blob"` class. To achieve 0 dependencies, the `blob` package is only listed as a suggested dependency but if you attach it, its print method will be used.

```{r}
library(blob)
decoded <- decode(hello)
decoded
```

We can convert the decoded base64 to characters and see how it worked.

```{r}
rawToChar(decoded[[1]])
```


### Vectorized 

Both `encode()` and `decode()` are vectorized. 

```{r}
lorem <- unlist(lorem::ipsum(5, 1,  5))
lorem

encoded <- encode(lorem)
encoded
```

We can decode all of these using `decode()` as well.

```{r}
decode(encoded)
```


## Encoding and decoding files

`b64` shines when encoding and decoding files. `encode_file()` and `decode_file()` both work by reading a file as a stream making it far faster than the alternative.

```{r message = FALSE, warn = FALSE}
tmp <- tempfile() 
fp <- "https://github.com/extendr/b64/blob/main/src/rust/vendor.tar.xz"

download.file(fp, tmp)

bench::mark(
  b64 = encode_file(tmp),
  base64enc = base64enc::base64encode(tmp)
)
```

While the encoding is very impressive, better yet is the decoding performance. 

```{r}
# create a temp file
tmp2 <- tempfile()

# encode it and write to tmep file
encode_file(tmp) |>
  charToRaw() |>
  writeBin(tmp2)

bench::mark(
  b64 = decode_file(tmp2),
  base64enc = base64enc::base64decode(file(tmp2))
)
```

## Alternative engines 

Out of the box, `b64` provides a number of pre-configured engines that can be used. The function `engine()` allows you to choose one of these different engines For example, `engine("url_safe")` provides a standard engine that uses a url-safe alphabet with padding.


```{r}
url_engine <- engine("url_safe")
url_safe_encoded <- encode("\xfa\xec U", url_engine)
url_safe_encoded
```

If we try to decode this using the standard engine, we will encounter an error. 

```{r error=TRUE}
decode(url_safe_encoded)
```

We can use our new engine to decode it.

```{r}
decode(url_safe_encoded, url_engine)
```

### Custom Engines

We can create custom engines with `new_engine()`. This allows us to provide our on alphabet and configuration. 

We can use one of the many predefined alphabets or create one our selves with `new_alphabet()`. We can also specify our engine config using `new_config()` which lets us choose whether or not to pad and how to handle decoding. 

```{r}
my_eng <- new_engine(
  alphabet("crypt"),
  new_config(TRUE, TRUE, "none")
)
```

This engine can be used to encode or decode text. 

```{r}
txt <- "lorem ipsum sit dolor amet"

encode(txt, my_eng)
```

Compare this to the standard encoder: 

```{r}
encode(txt)
```

Owner

  • Name: Extendr
  • Login: extendr
  • Kind: organization

Extension libraries for R in Rust

GitHub Events

Total
  • Issues event: 7
  • Watch event: 7
  • Issue comment event: 25
  • Push event: 36
  • Pull request event: 2
  • Fork event: 2
Last Year
  • Issues event: 7
  • Watch event: 7
  • Issue comment event: 25
  • Push event: 36
  • Pull request event: 2
  • Fork event: 2

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 6
  • Total pull requests: 5
  • Average time to close issues: 3 months
  • Average time to close pull requests: 2 days
  • Total issue authors: 5
  • Total pull request authors: 3
  • Average comments per issue: 5.67
  • Average comments per pull request: 1.6
  • Merged pull requests: 4
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 4
  • Pull requests: 1
  • Average time to close issues: about 1 month
  • Average time to close pull requests: less than a minute
  • Issue authors: 4
  • Pull request authors: 1
  • Average comments per issue: 7.25
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • JosiahParry (2)
  • eddelbuettel (1)
  • etiennebacher (1)
  • glin (1)
  • jcoloso (1)
  • LArkema (1)
Pull Request Authors
  • JosiahParry (6)
  • olivroy (2)
  • etiennebacher (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 490 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 8
  • Total maintainers: 1
cran.r-project.org: b64

Fast and Vectorized Base 64 Engine

  • Versions: 8
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 490 Last month
Rankings
Dependent packages count: 28.4%
Dependent repos count: 36.4%
Average: 49.9%
Downloads: 84.9%
Maintainers (1)
Last synced: 10 months ago

Dependencies

src/rust/Cargo.lock cargo
  • base64 0.21.7
  • either 1.9.0
  • extendr-api 0.6.0
  • extendr-macros 0.6.0
  • itertools 0.12.0
  • libR-sys 0.6.0
  • once_cell 1.19.0
  • paste 1.0.14
  • proc-macro2 1.0.76
  • quote 1.0.35
  • syn 2.0.48
  • unicode-ident 1.0.12
src/rust/Cargo.toml cargo
DESCRIPTION cran
  • blob * imports
  • rlang * imports
.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v3 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pkgdown.yaml actions
  • JamesIves/github-pages-deploy-action v4.4.1 composite
  • actions/checkout v3 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite