git.iko.soy/typeable/file-embed
on master help sign in
Use StringPrimL, expose bsToExp
commit06696a08ec210664fdcda9c1ddae2298a1c31131 authorMichael Snoyman <michael@snoyman.com> dateFri 23 May 2014, 10:05 (12 years ago) parenta629337
2 files changed+15−2
Data/FileEmbed.hs+14−1 file-embed.cabal+1−1
Data/FileEmbed.hs+14−1
@@ -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
file-embed.cabal+1−1
@@ -1,5 +1,5 @@
11name: file-embed
2−version: 0.0.6
2+version: 0.0.7
33license: BSD3
44license-file: LICENSE
55author: Michael Snoyman <michael@snoyman.com>