Is there an alternative to "Rucksack" to pack a directory's content into a virtual file system?

1 Like

Problem solved: The Rucksack developers have provided me with the solution (a big thank to them):

require "http/server"
require "rucksack"
require "mime"

server = do |context|
  path = context.request.path
  path = "/index.html" if path == "/"
  path = "./webroot#{path}"

    # Here we read the requested file from the Rucksack
    # and write it to the HTTP response. By default Rucksack
    # falls back to direct filesystem access in case the
    # executable has no Rucksack attached.
    context.response.content_type = MIME.from_filename(path)
  rescue Rucksack::FileNotFound
    context.response.status =
    context.response.print "404 not found :("

address = server.bind_tcp 8080
puts "Listening on http://#{address}"

# Here we statically reference the files to be included
# once - otherwise Rucksack wouldn't know what to pack.
{% for name in `find ./webroot -type f`.split('\n') %}
{% end %}

For the record, a popular alternative is GitHub - schovi/baked_file_system: Virtual File System for Crystal language. Embedding your assets into final binary.
It’s a bit easier to use than rucksack. The architecture of rucksack would certainly be more beneficial for huge files.

1 Like

Thank you very much!