Git Product home page Git Product logo

resourcetables's Introduction

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

resourcetables's People

Contributors

rattleycooper avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.