module

BakedFileSystem

A BakedFileSystem allows to include ("bake") static files into a compiled binary and make them accessible at runtime using their path.

Usage

# Using BakedFileSystem.load
class MyFileSystem
  extend BakedFileSystem
  bake_folder "path/to/root/folder"
end

# Creating a file manually
class MyFileSystem
  extend BakedFileSystem
  bake_file "hello-world.txt", "Hello World\n"
end

Constants

VERSION = {{ (`shards version /tmp/tmp.LImnKn/src/src/baked_file_system/../..`).chomp.stringify }}

Instance methods

bake_file(path : String, content)

Creates a BakedFile at path with content content and adds it to this file system.

Source
bake_file(file : BakedFile)

Adds a baked file to this file system.

Source
files

Returns all virtual files in this file system. These are the shared instances: use get for a file to read.

Source
get(path : String) : BakedFile

Returns a BakedFile at path.

Raises NoSuchFileError if the virtual file does not exist.

Source
get?(path : String) : BakedFile | Nil

Returns a BakedFile at path or nil if the virtual file does not exist.

The result is a new BakedFile over the baked bytes, read from the start. It is not shared with other callers, so reading it can't disturb (or be disturbed by) another fiber or thread reading the same path.

Source

Macros

bake_folder(path, dir = __DIR__, allow_empty = false)

Bakes all files in path into this baked file system. If path is relative, it will be based on dir which defaults to __DIR__. It will raise if there are no files found in path unless allow_empty is set to true.

Source
load(path, dir = __DIR__, allow_empty = false)

Creates a baked file system and loads contents of files in path. If path is relative, it will be based on dir which defaults to __DIR__. It will raise if there are no files found in path unless allow_empty is set to true.

DEPRECATED: Use extend BakedFileSystem and bake_folder instead.

Source

Nested types