Skip to contents

Writes file content extracted from Shinylive applications to disk, handling both text and binary content appropriately. Creates any necessary parent directories and ensures proper encoding of content. For binary files, automatically decodes the base64-encoded content before writing.

Usage

write_file_content(content, file_path, type = "text")

Arguments

content

Character string containing the file content. For binary files, this should be base64-encoded content. For text files, this should be the raw text content.

file_path

Character string specifying the path where the file should be written. Parent directories will be created if they don't exist.

type

Character string specifying the file type, either "text" (default) or "binary". Binary files are assumed to be base64 encoded, as this is the standard format for binary content in Shinylive applications.

Value

Invisible NULL, called for its side effect of writing a file to disk.

Details

The function handles two types of content:

Parent directories in the file path are automatically created if they don't exist using fs::dir_create() with recurse = TRUE.

Examples

# Writing a text file
write_file_content(
  content = "library(shiny)\n\nui <- fluidPage()",
  file_path = "app/app.R",
  type = "text"
)

# Write base64 encoded image
b64img <- paste0(
  "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAA",
  "DUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="
)
write_file_content(b64img, "test.png", type = "binary")