https://github.com/snoyberg/file-embed
Use Template Haskell to embed file contents directly.
https://github.com/snoyberg/file-embed
Last synced: 3 months ago
JSON representation
Use Template Haskell to embed file contents directly.
- Host: GitHub
- URL: https://github.com/snoyberg/file-embed
- Owner: snoyberg
- License: other
- Created: 2009-07-23T18:55:38.000Z (almost 16 years ago)
- Default Branch: master
- Last Pushed: 2025-02-24T08:47:41.000Z (4 months ago)
- Last Synced: 2025-03-31T15:35:23.617Z (3 months ago)
- Language: Haskell
- Homepage:
- Size: 93.8 KB
- Stars: 94
- Watchers: 5
- Forks: 28
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
- License: LICENSE
Awesome Lists containing this project
README
# file-embed   
Embed arbitrary files like JSON or plain text into your Haskell code as if they were written inside Haskell.
Note: This library uses Template Haskell for the embedding.
## Quickstart
Add [the latest version](https://hackage.haskell.org/package/file-embed) of `file-embed` to your
package description `.cabal` or Stack `package.yaml` file.Given the folder structure
```shell
$ tree
.
└── myapp
│ ├── app
│ │ └── Main.hs
│ ├── embedded.json
│ └── myapp.cabal
└── cabal.project
```you can embed a file as follows:
```haskell
-- file: Main.hs
{-# LANGUAGE TemplateHaskell #-}import qualified Data.ByteString as BS
import Data.FileEmbed (embedFileRelative)myFile :: BS.ByteString
myFile = $(embedFileRelative "embedded.json")
```The path to `embedFileRelative` is relative to the package root; the folder where the `.cabal` file is.
Take a look at the [Hackage documentation](https://hackage.haskell.org/package/file-embed/docs/Data-FileEmbed.html)
for more examples and variations.