Skip to content

Super simple compile time embedded resources, and remote runtime resources. Useful for making installers.

License

Notifications You must be signed in to change notification settings

RattleyCooper/resourcetables

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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

# 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")

About

Super simple compile time embedded resources, and remote runtime resources. Useful for making installers.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages