git.iko.soy/typeable/file-embed
on master help sign in
Use StringPrimL, expose bsToExp
06696a0Michael Snoyman
Data/FileEmbed.hs+14−1
@@ -29,10 +29,11 @@ module Data.FileEmbed
29 , injectFile
29 , injectFile
30 -- * Internal
30 -- * Internal
31 , stringToBs
31 , stringToBs
32+ , bsToExp
32 ) where
33 ) where
33
34
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)
38#else
39#else
@@ -118,10 +119,22 @@ pairToExp _root (path, bs) = do
118 return $! TupE [LitE $ StringL path, exp']
119 return $! TupE [LitE $ StringL path, exp']
119
120
120bsToExp :: B.ByteString -> Q Exp
121bsToExp :: 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
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
137+#endif
125
138
126stringToBs :: String -> B.ByteString
139stringToBs :: String -> B.ByteString
127stringToBs = B8.pack
140stringToBs = B8.pack
file-embed.cabal+1−1
@@ -1,5 +1,5 @@
1name: file-embed
1name: file-embed
2−version: 0.0.6
2+version: 0.0.7
3license: BSD3
3license: BSD3
4license-file: LICENSE
4license-file: LICENSE
5author: Michael Snoyman <michael@snoyman.com>
5author: Michael Snoyman <michael@snoyman.com>