R Bindings to 'Rust' 'IPLD' Libraries

Provides R bindings to decode DAG-CBOR (Directed Acyclic Graph Concise Binary Object Representation) encoded data, CIDs (Content Identifiers), and CAR (Content Addressable aRchive) files using the 'Rust' 'IPLD' (InterPlanetary Linked Data) crates 'ipld-core' < https://github.com/ipld/rust-ipld-core> and 'serde_ipld_dagcbor' < https://github.com/ipld/serde_ipld_dagcbor>. This is especially useful for working with data from 'IPFS' (InterPlanetary File System) and 'AtProto' (Bluesky) applications.


libipldr

R-CMD-check extendr CRAN_Download_Badge CRANstatus

The goal of libipldr is to make it possible to translate DAG-CBOR encoded data in R. This is mostly useful for the atrrr package that can stream from the Bluesky firehose.

Installation

You can install from CRAN with:

install.packages("libipldr")

Or install the development version from GitHub with:

# install.packages("pak")
pak::pak("JBGruber/libipldr")

Example

Decode CID:

library(libipldr)
decode_cid("bafyreig7jbijxpn4lfhvnvyuwf5u5jyhd7begxwyiqe7ingwxycjdqjjoa")
#> $version
#> [1] 1
#> 
#> $codec
#> [1] 113
#> 
#> $hash
#> $hash$code
#> [1] 18
#> 
#> $hash$size
#> [1] 32
#> 
#> $hash$digest
#>  [1] df 48 50 9b bd bc 59 4f 56 d7 14 b1 7b 4e a7 07 1f c2 43 5e d8 44 09 f4 34
#> [26] d6 be 04 91 c1 29 70

Decode DAG-CBOR:

cbor_data <- as.raw(c(
  0xa2,
  0x61,
  0x61,
  0x65,
  0x48,
  0x65,
  0x6c,
  0x6c,
  0x6f,
  0x61,
  0x62,
  0x66,
  0x57,
  0x6f,
  0x72,
  0x6c,
  0x64,
  0x21
))
decode_dag_cbor(cbor_data)
#> $a
#> [1] "Hello"
#> 
#> $b
#> [1] "World!"

What is this good for?

Mainly I wanted to have this to decode the firehose stream from Bluesky:

library(httr2)
# open connection to firehose
firehose <- request(
  "wss://bsky.network/xrpc/com.atproto.sync.subscribeRepos"
) |>
  req_perform_connection()

# stream 5 Mb
results_raw <- firehose |>
  resp_stream_raw(kb = 5000)

close(firehose)

# decode the stream
results <- decode_dag_cbor_multi(results_raw)

# extract operations
library(purrr)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
events_df <- map(results, function(res) {
  pluck(res, "ops", 1)
}) |>
  bind_rows()
events_df
#> # A tibble: 1,000 × 4
#>    action cid                                                        path  prev 
#>    <chr>  <chr>                                                      <chr> <chr>
#>  1 create bafyreiaqj6yznc4io4i4zxizfdklgd7urakvbexrepeopeuiybqmea37… app.… <NA> 
#>  2 create bafyreigokr46kgovyvyext6gc2gtgvo35f7qanrxg2vg4ydylqzewvw5… app.… <NA> 
#>  3 create bafyreibkbewi5znuszchikeyvlmrlzjpi2x3dyzvkwazkxbspsbfvynv… app.… <NA> 
#>  4 delete <NA>                                                       app.… bafy…
#>  5 create bafyreibicjzpjk3jtbuxhhst5iyjbxdviahiy3qzck7243akvk3n4gsk… app.… <NA> 
#>  6 create bafyreih6f35k2rd75e2w3zyispypoaobr3lsjnpyaeetvkgn6syi32cb… app.… <NA> 
#>  7 create bafyreieaggwdyljyv6b2rct4oe5ve5n275d76mk6ygvg2zo5kbpzkxtj… app.… <NA> 
#>  8 create bafyreihmfjabuhwr46ifdnmdn6hy6edbshdgkhjdpa7kb7f5g2qrlrka… app.… <NA> 
#>  9 create bafyreicz3oubtna6tdbt4aqin2hlq35rdkgqyfmtxlagbec5nkvmepkz… app.… <NA> 
#> 10 create bafyreifq4gidsfxx5ayubokvmnh6lhdbbtv3rx7vyo4xea6lh7q64vjd… app.… <NA> 
#> # ℹ 990 more rows

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("libipldr")

0.2.0 by Johannes B. Gruber, a day ago


https://github.com/JBGruber/libipldr


Report a bug at https://github.com/JBGruber/libipldr/issues


Browse source code at https://github.com/cran/libipldr


Authors: Johannes B. Gruber [aut, cre, cph] (ORCID: , Ilya Siamionau [ctb, cph] (Author of the original python-libipld Rust implementation) , Authors of the dependency Rust crates [cph] (see inst/AUTHORS file)


Documentation:   PDF Manual  


MIT + file LICENSE license


Suggests testthat, rextendr, httr2, jsonlite, spelling

System requirements: Cargo (Rust's package manager), rustc >= 1.81


Suggested by atrrr.


See at CRAN