Skip to content

Commit

Permalink
Add embedFileRelative function.
Browse files Browse the repository at this point in the history
  • Loading branch information
my-name-is-lad committed Jan 24, 2024
1 parent 548430d commit 8f31bec
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Data/FileEmbed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
module Data.FileEmbed
( -- * Embed at compile time
embedFile
, embedFileRelative
, embedFileIfExists
, embedOneFileOf
, embedDir
Expand Down Expand Up @@ -63,7 +64,7 @@ import qualified Data.ByteString.Internal as B
import System.Directory (doesDirectoryExist, doesFileExist,
getDirectoryContents, canonicalizePath)
import Control.Exception (throw, tryJust, ErrorCall(..))
import Control.Monad (filterM, guard)
import Control.Monad ((<=<), filterM, guard)
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as B8
import Control.Arrow ((&&&), second)
Expand All @@ -90,6 +91,11 @@ embedFile fp =
#endif
(runIO $ B.readFile fp) >>= bsToExp

-- | Embed a file file in your source code.
-- Unlike 'embedFile', path is given relative to project root.
embedFileRelative :: FilePath -> Q Exp
embedFileRelative = embedFile <=< makeRelativeToProject

-- | Maybe embed a single file in your source code depending on whether or not file exists.
--
-- Warning: When a build is compiled with the file missing, a recompile when the file exists might not trigger an embed of the file.
Expand Down

0 comments on commit 8f31bec

Please sign in to comment.