@@ -18,6 +18,10 @@ import WaiAppStatic.Types
1818import WaiAppStatic.Storage.Filesystem (defaultWebAppSettings)
1919import qualified Data.ByteString as B
2020import qualified Data.ByteString.Lazy as BL
21+#if !MIN_VERSION_template_haskell(2, 8, 0)
22+import qualified Data.ByteString.Char8 as B8
23+import qualified Data.ByteString.Lazy.Char8 as BL8
24+#endif
2125import qualified Data.HashMap.Strict as M
2226import qualified Data.Text as T
2327import qualified Data.Text.Encoding as T
@@ -71,15 +75,30 @@ data ReloadEntry = ReloadEntry {
7175-- the IORef will always be holding (NoFinalizers, []). Therefore
7276-- unsafeDupablePerformIO is safe.
7377bytestringE :: B.ByteString -> ExpQ
78+#if MIN_VERSION_template_haskell(2, 8, 0)
7479bytestringE b = [| unsafeDupablePerformIO (unsafePackAddressLen (I# $lenE) $ctE) |]
7580 where
7681 lenE = litE $ intPrimL $ toInteger $ B.length b
7782 ctE = litE $ stringPrimL $ B.unpack b
83+#else
84+bytestringE b =
85+ [| B8.pack $s |]
86+ where
87+ s = litE $ stringL $ B8.unpack b
88+#endif
89+
7890bytestringLazyE :: BL.ByteString -> ExpQ
91+#if MIN_VERSION_template_haskell(2, 8, 0)
7992bytestringLazyE b = [| unsafeDupablePerformIO (unsafePackAddressLen (I# $lenE) $ctE) |]
8093 where
8194 lenE = litE $ intPrimL $ toInteger $ BL.length b
8295 ctE = litE $ stringPrimL $ BL.unpack b
96+#else
97+bytestringLazyE b =
98+ [| B8.pack $s |]
99+ where
100+ s = litE $ stringL $ BL8.unpack b
101+#endif
83102
84103-- | A template haskell expression which creates either an EmbeddedEntry or ReloadEntry.
85104mkEntry :: EmbeddableEntry -> ExpQ