Skip to contents

Ropendal keeps bytes as the transport primitive and makes conversion explicit.

library(Ropendal)

root <- file.path(tempdir(), "ropendal-serializers")
unlink(root, recursive = TRUE)
dir.create(root, recursive = TRUE)
fs <- opendal("fs", root = root)

Raw and text modes

mode = "raw" is the default. mode = "text" wraps UTF-8 text conversions.

fs_write(fs, "text.txt", "hello", mode = "text")
#> [1] TRUE
raw <- fs_read(fs, "text.txt", mode = "text")
raw
#> [1] "hello"

Serializers for R objects

Use serial_config() with mode = "serial" for explicit object materialization.

note <- structure(list(text = "ok"), class = "ropendal_note")
sc <- serial_config(
  "ropendal_note",
  sfunc = function(x) charToRaw(x$text),
  ufunc = function(x) structure(list(text = rawToChar(x)), class = "ropendal_note")
)
fs_write(fs, "obj.rds", note, mode = "serial", serial_config = sc)
#> [1] TRUE
obj <- fs_read(fs, "obj.rds", mode = "serial", serial_config = sc)
obj$text
#> [1] "ok"

Native codecs

codec_config() is a byte transform layer (identity, gzip, zlib) that applies around transport bytes.

cc <- codec_config("gzip")
fs_write(
  fs,
  "blob.bin",
  as.raw(1:6),
  mode = "codec",
  codec = cc
)
#> [1] TRUE
fs_read(fs, "blob.bin", mode = "codec", codec = cc)
#> [1] 01 02 03 04 05 06