baked_file_system
Baked File System
Include (bake them) static files into your binary and access them anytime you need.
Installation
Add this to your application's shard.yml
:
dependencies:
baked_file_system:
github: schovi/baked_file_system
Usage
Load library with:
require "baked_file_system"
Load folder with absolute path
class FileStorage
BakedFileSystem.load("/home/my_name/work/crystal_project/public")
end
Better and more often usage will be, when you need to locate files in your repository That repository can be in different locations (imagine more ppl working on same program)
class FileStorage
BakedFileSystem.load("../public")
end
And finally how to get files from that storage
file = FileStorage.get("path/to/file.png")
file.read # returns content of file
file.encoded # returns encoded content, which can be used in base64 urls
file.name # returns name of file
file.mime_type # returns mime type
file.size # returns size of original file
When try to get missing file, BakedFileSystem thows BakedFileSystem::NoSuchFileError exception
path = "missing/file"
begin
FileStorage.get(path)
rescue BakedFileSystem::NoSuchFileError
puts "File #{path} is missing"
end
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 - creator, maintainer
Repository
baked_file_system
Owner
Statistic
- 0
- 0
- 0
- 0
- 0
- over 6 years ago
- June 5, 2018
License
MIT License
Links
Synced at
Thu, 07 Nov 2024 14:33:11 GMT
Languages