This tool allows you to embed files and directories into scripting languages like JavaScript and Python.
The File Embedder works by:
- Reading input files or directories
- Converting file contents to base64
- Generating a nested object structure
- Creating utility functions for easy access
- Outputting the result in the chosen language
This approach allows efficient embedding and retrieval of file contents within scripts.
- Embed single files or entire directories
- Supports JavaScript and Python output (Python support is experimental)
- The embedded files are fully typed in typescript
- Preserves directory structure in the embedded output
- Provides utility functions to easily access embedded files
deno run --allow-read --allow-writes jsr:@sigma/embed <input_file_or_directory> <input_file2> [...] --lang <js|py><input_file_or_directory>: Path to the file or directory you want to embed--langor-l: Output language (js or py)--helpor-h: Show help information
The tool generates a file named embedded_files.<lang> in the current
directory. This file contains:
- A nested object structure representing the embedded files and directories
- Utility functions to access the embedded data
For JavaScript, the output file exports an object with:
files: The nested object structure of embedded filesget(value): A function to get the file content as a Uint8ArraygetString(value): A function to get the file content as a string
deno run --allow-read --allow-write jsr:@sigma/embed ./assets --lang jsThis command will embed all files in the ./assets directory into a file named
embedded_files.js.
You can now use it like this:
Example 1
import $ from "./embedded_files.js";
console.log($.getString($.files.assets.file1));This tool can also be used as a library.
import { embedFiles } from "jsr:@sigma/embed";
await embedFiles(["./assets"], "js");