No description
Find a file
2024-02-19 15:32:09 -05:00
.github/workflows Add nim v2 to CI 2023-04-12 23:12:20 -04:00
changes v0.2.0 2024-02-19 15:09:02 -05:00
src absolute fix 2024-02-19 15:32:09 -05:00
tests Prevent escaping to parent directory when in non-embed mode 2023-03-24 11:50:51 -04:00
CHANGELOG.md v0.2.0 2024-02-19 15:09:02 -05:00
embedfs.nimble v0.2.0 2024-02-19 15:09:02 -05:00
README.md Published package 2023-03-23 22:04:52 -04:00

embedfs

Embed directories of files in your executable. It's like staticRead/slurp for whole directories.

.github/workflows/tests.yml

Installation

nimble install embedfs

Usage

import embedfs
const data = embedDir("data")
echo data.get("somefile.txt").get()
doAssert data.get("nonexisting.txt").isNone

for filename in data.listDir():
  echo filename

for filename in data.walk():
  echo filename

You can also change from embedding at compile-time (the default) to reading files from disk at runtime for testing purposes with embed = false, because sometimes it's nice to not have to recompile the whole program just to get new assets:

import embedfs
const data = embedDir("data", embed = false)
writeFile("data"/"foo.txt", "foo")
doAssert data.get("foo.txt") == some("foo")
writeFile("data"/"foo.txt", "new value")
doAssert data.get("foo.txt") == some("new value")