https://github.com/rattleycooper/resourcetables
Super simple compile time embedded resources, and remote runtime resources. Useful for making installers.
https://github.com/rattleycooper/resourcetables
embedded-resources installer-tools remote-asset
Last synced: 28 days ago
JSON representation
Super simple compile time embedded resources, and remote runtime resources. Useful for making installers.
- Host: GitHub
- URL: https://github.com/rattleycooper/resourcetables
- Owner: RattleyCooper
- License: mit
- Created: 2024-03-01T04:30:08.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-16T00:03:27.000Z (about 1 year ago)
- Last Synced: 2024-04-17T02:16:56.247Z (about 1 year ago)
- Topics: embedded-resources, installer-tools, remote-asset
- Language: Nim
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# resourcetables
Super simple compile time embedded resources, and remote runtime resources. Useful if you're trying to ship an application and want to create an offline or online installer.## Install
`nimble install https://github.com/RattleyCooper/resourcetables`
## Examples
```nim
import resourcetables# Embed an entire directory at compile time
const assets = embed("asset-folder")
echo assets["some-file.txt"]# Compress directory
const compressedAssets = staticCompress("asset-folder")# uncompress & extract at runtime
compressedAssets.uncompress()# if you have zippy imported and don't need to extract
let fileContents = compressedAssets["some-file.txt].uncompress()# Embed specific resources at compile time
# You could also use staticCompress("specificRes"):
# if you want to compress specific files.
embed("specificRes"):
"another/file.txt"
# use triple quoted string to retain full path
"""other/stuff.png"""# Access embedded resources
specificRes["file.txt]
specificRes["other/stuff.png]# Fetch remote resources at runtime. 3 infix operators
# are available for saving data and/or rewriting keys.remote("online"):
# Store resulting data using the key "gF1bsWr.jpeg"
"https://i.imgur.com/gF1bsWr.jpeg"# Save resulting data to "new.jpeg"
"https://i.imgur.com/gF1bsWr.jpeg" -> "new.jpeg"# Use "new.jpeg" as the key in the `online` table
"https://i.imgur.com/gF1bsWr.jpeg" <- "new.jpeg"# Save data to "new.jpeg" and use "new.jpeg" as
# the key in the `online` table.
"https://i.imgur.com/gF1bsWr.jpeg" <-> "new.jpeg"
```# Creating an Installer
```nim
# Embed our game files into the binary at compile time
# and extract them when the binary is executed.import resourcetables
# Compile-time
embed("data"):
"D:/Code/Nim/playground/nicopg/SDL2.dll"
"D:/Code/Nim/playground/nicopg/conway.exe"embed("assets"):
"D:/Code/Nim/playground/nicopg/assets/font.png"
"D:/Code/Nim/playground/nicopg/assets/font.png.dat"
"D:/Code/Nim/playground/nicopg/assets/icon.png"# Runtime
data.extract()
assets.extract("assets")
```