Skip to content

Commit

Permalink
Implementation to load composition from files
Browse files Browse the repository at this point in the history
  • Loading branch information
Viir committed Feb 13, 2020
1 parent e074478 commit e4c5fd8
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Text;

namespace Kalmit
{
static public class LoadFromLocalFilesystem
{
static public Composition.TreeComponent LoadTreeFromPath(string path)
{
if (File.Exists(path))
return new Composition.TreeComponent { BlobContent = File.ReadAllBytes(path).ToImmutableList() };

if (!Directory.Exists(path))
return null;

var treeEntries =
Directory.EnumerateFileSystemEntries(path)
.Select(fileSystemEntry =>
{
var name = (IImmutableList<byte>)Encoding.BigEndianUnicode.GetBytes(Path.GetRelativePath(path, fileSystemEntry)).ToImmutableList();

return (name, LoadTreeFromPath(fileSystemEntry));
})
.ToImmutableList();

return new Composition.TreeComponent
{
TreeContent = treeEntries,
};
}
}
}

0 comments on commit e4c5fd8

Please sign in to comment.