@@ -29,10 +29,11 @@ module Data.FileEmbed
2929 , injectFile
3030 -- * Internal
3131 , stringToBs
32+ , bsToExp
3233 ) where
3334
3435import Language.Haskell.TH.Syntax
35− ( Exp (AppE, ListE, LitE, TupE, SigE)
36+ ( Exp (AppE, ListE, LitE, TupE, SigE, VarE)
3637#if MIN_VERSION_template_haskell(2,5,0)
3738 , Lit (StringL, StringPrimL, IntegerL)
3839#else
@@ -118,10 +119,22 @@ pairToExp _root (path, bs) = do
118119 return $! TupE [LitE $ StringL path, exp']
119120
120121bsToExp :: B.ByteString -> Q Exp
122+#if MIN_VERSION_template_haskell(2, 5, 0)
123+bsToExp bs =
124+ return $ VarE 'unsafePerformIO
125+ `AppE` (VarE 'unsafePackAddressLen
126+ `AppE` LitE (IntegerL $ fromIntegral $ B8.length bs)
127+#if MIN_VERSION_template_haskell(2, 8, 0)
128+ `AppE` LitE (StringPrimL $ B.unpack bs))
129+#else
130+ `AppE` LitE (StringPrimL $ B8.unpack bs))
131+#endif
132+#else
121133bsToExp bs = do
122134 helper <- [| stringToBs |]
123135 let chars = B8.unpack bs
124136 return $! AppE helper $! LitE $! StringL chars
137+#endif
125138
126139stringToBs :: String -> B.ByteString
127140stringToBs = B8.pack