# Idea for a trivial virtual file system for archiving text-based resources (html, css, js, etc. for a server)

**URL:** <https://forum.crystal-lang.org/t/idea-for-a-trivial-virtual-file-system-for-archiving-text-based-resources-html-css-js-etc-for-a-server/5417>\
**Category:** Community\
**Created:** [February 23, 2023, 3:36pm UTC](https://forum.crystal-lang.org/t/idea-for-a-trivial-virtual-file-system-for-archiving-text-based-resources-html-css-js-etc-for-a-server/5417 "2023-02-23T15:36:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![serge-hulne](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/serge-hulne/32/1211_2.png) [@serge-hulne](https://forum.crystal-lang.org/u/serge-hulne)\
**Post date:** [February 23, 2023, 3:36pm UTC](https://forum.crystal-lang.org/t/idea-for-a-trivial-virtual-file-system-for-archiving-text-based-resources-html-css-js-etc-for-a-server/5417/1 "2023-02-23T15:36:36Z")

</div>

Corresponding repository:

> **[GitHub - serge-hulne/bakerstreet: Virtual file system for servers written in...](https://github.com/serge-hulne/bakerstreet)**
>
> Virtual file system for servers written in Crystal lang (aimed at embedding text resources (.html, .css,. js) in app) - GitHub - serge-hulne/bakerstreet: Virtual file system for servers written in ...

The idea is basically that it creates (from the resources folder) a file archive.cr which contains a Hash literal, which in turns holds the paths as keys and the file content as values.

The aim is embedding resource files in a desktop Webview-based app (in a OS independent manner).

```auto
require "path"
require "dir"
require "./archive.cr"

# TODO 1 make it recursive (tree structure)
# TODO 2 replace \n by a portable (OS dependent) newline symbol
# TODO 3 Test in combination with a server.
# TODO 4 Test on Windows.

Root = Dir.new("public")
Root_path = Path.new("public")
Dico = Hash(String, String).new
Arc = "archive.cr"

def to_path(file)
  return Root_path.join(file).to_s
end

Root.each_child do |child|
  path = Root_path.join(child)
  content = File.read(path)
  Dico[path.to_s] = content.to_s
end

File.open(Arc, "w") do |file|
  file.print("def get_archive()
    \n\treturn Hash {\n\n")
end

File.open(Arc, "a") do |file|
  Dico.each_key do |key|
    token = %{"#{key}" => %{#{Dico[key]}}, \n}
    file.print(token)
    file.print("\n")
  end
end

File.open(Arc, "a") do |file|
  file.print("}")
end

File.open(Arc, "a") do |file|
  file.print("\n\nend")
end

arc = get_archive()

# arc.each do |item|
# p item
# puts "\n- - -\n"
# end

puts "file = #{arc[to_path("index.html")]}"

```

the (generated) archive.cr file looks like :

```auto
def get_archive() 
    
	return Hash {

"public/index.html" => %{<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    Test
</body>
</html>}, 

"public/two.html" => %{<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    Two
</body>
</html>}, 

}

end

```

---

<div class="post-metadata">

**Author:** ![serge-hulne](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/serge-hulne/32/1211_2.png) [@serge-hulne](https://forum.crystal-lang.org/u/serge-hulne)\
**Post date:** [February 24, 2023, 9:55am UTC](https://forum.crystal-lang.org/t/idea-for-a-trivial-virtual-file-system-for-archiving-text-based-resources-html-css-js-etc-for-a-server/5417/2 "2023-02-24T09:55:37Z")

</div>

I improved the documentation for the “Bakerstreet” archiver;

> **[GitHub - serge-hulne/bakerstreet: Virtual file system for servers written in...](https://github.com/serge-hulne/bakerstreet)**
>
> Virtual file system for servers written in Crystal lang (aimed at embedding text resources (.html, .css,. js) in app) - GitHub - serge-hulne/bakerstreet: Virtual file system for servers written in ...
