module BakedFileSystem
Overview
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
Defined in:
baked_file_system.crbaked_file_system/version.cr
loader/byte_counter.cr
loader/loader.cr
loader/stats.cr
Constant Summary
-
VERSION =
"0.12.0"
Macro Summary
-
bake_folder(path, dir = __DIR__, allow_empty = false, include_dotfiles = false, max_size = nil)
Bakes all files in path into this baked file system.
-
load(path, dir = __DIR__, allow_empty = false)
Creates a baked file system and loads contents of files in path.
Instance Method Summary
-
#bake_file(path : String, content)
Creates a
BakedFileat path with content content and adds it to this file system. -
#bake_file(file : BakedFile)
Adds a baked file to this file system.
-
#files : Array(BakedFileSystem::BakedFile)
Returns all virtual files in this file system.
-
#get(path : String) : BakedFile
Returns a
BakedFileat path. -
#get(path : String, &block : BakedFile -> T) : T forall T
Opens a file and yields it to the block, ensuring it's closed afterwards.
-
#get?(path : String) : BakedFile | Nil
Returns a
BakedFileat path ornilif the virtual file does not exist. -
#get?(path : String, &block : BakedFile -> T) : T | Nil forall T
Opens a file and yields it to the block, ensuring it's closed afterwards.
Macro Detail
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.
The max_size parameter can be used to enforce a maximum total compressed size limit (in bytes).
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.
Instance Method Detail
Creates a BakedFile at path with content content and adds it to this file system.
Returns a BakedFile at path.
Raises NoSuchFileError if the virtual file does not exist.
Opens a file and yields it to the block, ensuring it's closed afterwards.
MyFiles.get("file.txt") do |file|
file.gets_to_end
end
Returns a BakedFile at path or nil if the virtual file does not exist.
Opens a file and yields it to the block, ensuring it's closed afterwards. Returns nil if the file does not exist.
MyFiles.get?("file.txt") do |file|
file.gets_to_end
end