@@ -29,10 +29,11 @@ module Data.FileEmbed
29 , injectFile
29 , injectFile
30 -- * Internal
30 -- * Internal
31 , stringToBs
31 , stringToBs
34import Language.Haskell.TH.Syntax
35import Language.Haskell.TH.Syntax
35− ( Exp (AppE, ListE, LitE, TupE, SigE)
36+ ( Exp (AppE, ListE, LitE, TupE, SigE, VarE)
36#if MIN_VERSION_template_haskell(2,5,0)
37#if MIN_VERSION_template_haskell(2,5,0)
37 , Lit (StringL, StringPrimL, IntegerL)
38 , Lit (StringL, StringPrimL, IntegerL)
@@ -118,10 +119,22 @@ pairToExp _root (path, bs) = do
118 return $! TupE [LitE $ StringL path, exp']
119 return $! TupE [LitE $ StringL path, exp']
120bsToExp :: B.ByteString -> Q Exp
121bsToExp :: B.ByteString -> Q Exp
122+#if MIN_VERSION_template_haskell(2, 5, 0)
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))
130+ `AppE` LitE (StringPrimL $ B8.unpack bs))
121bsToExp bs = do
133bsToExp bs = do
122 helper <- [| stringToBs |]
134 helper <- [| stringToBs |]
123 let chars = B8.unpack bs
135 let chars = B8.unpack bs
124 return $! AppE helper $! LitE $! StringL chars
136 return $! AppE helper $! LitE $! StringL chars
126stringToBs :: String -> B.ByteString
139stringToBs :: String -> B.ByteString
127stringToBs = B8.pack
140stringToBs = B8.pack