https://github.com/leighmcculloch/deno-embed
Embed files into demo applications by embedding them into a JSON file and importing natively into the demo app.
https://github.com/leighmcculloch/deno-embed
deno embed
Last synced: 2 months ago
JSON representation
Embed files into demo applications by embedding them into a JSON file and importing natively into the demo app.
- Host: GitHub
- URL: https://github.com/leighmcculloch/deno-embed
- Owner: leighmcculloch
- License: mit
- Created: 2022-04-01T07:09:31.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-04-02T04:35:43.000Z (about 4 years ago)
- Last Synced: 2025-06-03T19:26:40.561Z (about 1 year ago)
- Topics: deno, embed
- Language: TypeScript
- Homepage: https://deno.land/x/embed
- Size: 12.7 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# deno-embed
[](https://deno.land/x/embed)
Embed files into deno applications by embedding them into a JSON file and importing natively into the deno app.
CLI: https://deno.land/x/embed/cli.ts
Mod: https://deno.land/x/embed/mod.ts
## Usage
### CLI
```
deno run --allow-read --allow-write \
https://deno.land/x/embed/cli.ts \
-i dir1 -i dir2 \
-o embed.json
```
### Import
```ts
import embed from "./embed.json" assert { type: "json" };
console.log(embed["dir1/file1"].contents);
```
### Import using Embed
[](https://doc.deno.land/https://deno.land/x/embed/mod.ts/~/Embed)
```ts
import { Embed } from "https://deno.land/x/embed/mod.ts";
import embedObj from "./embed.json" assert { type: "json" };
const embed = Embed.from(embedObj);
// Read a file into a Uint8Array.
_ = embed.readFile("dir1/file1");
// Read a text file into a string.
_ = embed.readTextFile("dir1/file2");
// Walk a directory structure.
for (const entry of embed.walk("dir1")) {
// ...
}
```