A fake file system for Deno binaries by Mandarine.
Leaf is a fake file system for Deno binaries. This means, you can save your files along with the binary generated by deno compile
, this way, you can put all your files together in a single executable which leads to easier deployments and a more compacted deliverable output.
To use Leaf in your application, you must use the Leaf File System APIs instead of Deno's.
The compile
method is responsible for creating a binary with your resources in it. compile
takes one argument which is the options to include.
import { Leaf } from "https://deno.land/x/leaf@v1.0.2/mod.ts";
Leaf.compile({
modulePath: "./myEntryPoint.ts",
contentFolders: ["./resources"]
})
modulePath
and contentFolders
are necessary.
modulePath
: File to be compiled into a binary.contentFolders
: Folders to be attached to the binary.
Synchronously reads and returns the entire contents of a file as an array of bytes. TextDecoder
can be used to transform the bytes to string if required. Reading a directory returns an empty data array.
import { Leaf } from "https://deno.land/x/leaf@v1.0.2/mod.ts";
const decoder = new TextDecoder("utf-8");
const data = Leaf.readFileSync("hello.txt");
console.log(decoder.decode(data));
Reads and returns the entire contents of a file as an array of bytes. TextDecoder
can be used to transform the bytes to string if required. Reading a directory returns an empty data array.
import { Leaf } from "https://deno.land/x/leaf@v1.0.2/mod.ts";
const decoder = new TextDecoder("utf-8");
const data = await Leaf.readFile("hello.txt");
console.log(decoder.decode(data));
Synchronously reads and returns the entire contents of a file as utf8 encoded string.
import { Leaf } from "https://deno.land/x/leaf@v1.0.2/mod.ts";
const data = Leaf.readTextFileSync("hello.txt");
console.log(data);
Reads and returns the entire contents of a file as utf8 encoded string.
import { Leaf } from "https://deno.land/x/leaf@v1.0.2/mod.ts";
const data = await Leaf.readTextFile("hello.txt");
console.log(data);
file1.ts:
import { Leaf } from "https://deno.land/x/leaf@v1.0.2/mod.ts";
Leaf.compile({
modulePath: "./myEntryPoint.ts",
contentFolders: ["./resources"]
})
./resources/text.txt
Hello World
myEntryPoint.ts:
import { Leaf } from "https://deno.land/x/leaf@v1.0.2/mod.ts";
console.log(Leaf.readTextFileSync("./resources/text.txt"));
deno run --allow-all --unstable _myEntryPoint.ts
./myEntryPoint (.exe if windows)
# output: Hello World
For questions & community support, please visit our Discord Channel or join us on our twitter.
In order to submit improvements to the code, open a PR and wait for it to review. We appreciate you doing this.
We would love to have you in our community, please submit an issue to provide information about a bug, feature, or improvement you would like.
- Author : Andres Pirela
- Website : https://www.mandarinets.org/
- Twitter : @mandarinets
- Discord : Click here