baked_file_system v0.11.0
Baked File System
Include (bake them) static files into a binary at compile time and access them anytime you need.
Installation
Add this to your application's shard.yml
:
dependencies:
baked_file_system:
github: schovi/baked_file_system
version: 0.10.0
Usage
A custom type that extends BakedFileSystem
is used as a file system. The macro bake_folder
bakes all files in a given path into the virtual file system. Both relative and absolute paths are supported, as well as baking multiple folders.
You can control whether dotfiles files and folders (those starting with a dot, like .gitignore
or .hidden/
) are included using the include_dotfiles
option (default: false
).
require "baked_file_system"
class FileStorage
extend BakedFileSystem
bake_folder "/home/my_name/work/crystal_project/public"
bake_folder "../public", include_dotfiles: true
end
Files can be loaded using get
and get?
class methods.
file = FileStorage.get("path/to/file.png")
file.gets_to_end # returns content of file
file.path # returns path of file
file.size # returns size of original file
When try to get missing file, get
raises a BakedFileSystem::NoSuchFileError
exception while get?
returns nil
.
begin
FileStorage.get "missing/file"
rescue BakedFileSystem::NoSuchFileError
puts "File #{path} is missing"
end
FileStorage.get? "missing/file" # => nil
Development
TODO: Write development instructions here
Contributing
- Fork it ( https://github.com/schovi/baked_file_system/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- schovi David Schovanec
- straight-shoota Johannes Müller
baked_file_system
- 179
- 20
- 3
- 65
- 0
- 25 days ago
- June 24, 2016
MIT License
Tue, 01 Jul 2025 09:50:48 GMT