git.iko.soy/typeable/file-embed
on master help sign in
Using String literal instead of int list for efficiency
commit8a1e68f92147e7029be6d5b52ebd3aa1776981c6 authorMichael Snoyman <michael@snoyman.com> dateMon 24 Aug 2009, 21:46 (17 years ago) parent1362635
2 files changed+10−10
Data/FileEmbed.hs+9−9 file-embed.cabal+1−1
Data/FileEmbed.hs+9−9
@@ -5,8 +5,8 @@ module Data.FileEmbed
55 ) where
66
77import Language.Haskell.TH (runQ,
8− Exp(AppE, ListE, LitE, TupE),
9− Lit(IntegerL, StringL),
8+ Exp (AppE, ListE, LitE, TupE),
9+ Lit (StringL),
1010 Q,
1111 runIO)
1212import System.Directory (doesDirectoryExist, doesFileExist,
@@ -30,13 +30,13 @@ pairToExp (path, bs) = do
3030
3131bsToExp :: B.ByteString -> Q Exp
3232bsToExp bs = do
33− pack <- runQ [| B.pack |]
34− return $!
35− AppE pack .
36− ListE .
37− map (LitE . IntegerL . fromIntegral) .
38− B.unpack $
39− bs
33+ helper <- runQ [| stringToBs |]
34+ let octets = B.unpack bs
35+ let chars = map (toEnum . fromEnum) octets
36+ return $! AppE helper $! LitE $! StringL chars
37+
38+stringToBs :: String -> B.ByteString
39+stringToBs = B.pack . map (toEnum . fromEnum)
4040
4141notHidden :: FilePath -> Bool
4242notHidden ('.':_) = False
file-embed.cabal+1−1
@@ -1,5 +1,5 @@
11name: file-embed
2−version: 0.0.0
2+version: 0.0.1
33license: BSD3
44license-file: LICENSE
55author: Michael Snoyman <michael@snoyman.com>