Use crypto-conduit for base64md5File.

This commit is contained in:
Felipe Lessa 2012-01-07 01:24:19 -02:00
parent bcca4e4dc4
commit af352c5ed0
2 changed files with 7 additions and 18 deletions

View File

@ -57,8 +57,10 @@ import Data.List (intercalate)
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
import Crypto.Conduit (sinkHash)
import Crypto.Hash.MD5 (MD5)
import qualified Data.ByteString.Lazy as L
import Data.Digest.Pure.MD5
import qualified Data.ByteString.Base64
import qualified Data.ByteString.Char8 as S8
import qualified Data.Serialize
@ -313,22 +315,8 @@ mkStaticFilesList fp fs routeConName makeHash = do
base64md5File :: Prelude.FilePath -> IO String
base64md5File file = do
bss <- C.runResourceT $ CB.sourceFile file C.$$ CL.consume
return $ base64md5 $ L.fromChunks bss
-- FIXME I'd like something streaming instead
{-
fmap (base64 . finalize) $ E.run_ $
EB.enumFile file E.$$ EL.fold go (md5InitialContext, "")
where
go (context, prev) next = (md5Update context prev, next)
finalize (context, end) = md5Finalize context end
-}
-- | Calculates the MD5 hash of the given lazy bytestring,
-- encodes it using Base64 and then return the 8 first
-- characters.
base64md5 :: L.ByteString -> String
base64md5 = base64 . md5
hash <- C.runResourceT $ CB.sourceFile file C.$$ sinkHash
return $ base64 $ Data.Serialize.encode (hash :: MD5)
base64 :: MD5Digest -> String
base64 = map tr

View File

@ -28,7 +28,6 @@ library
, old-time >= 1.0
, yesod-core >= 0.10 && < 0.11
, base64-bytestring >= 0.1.0.1 && < 0.2
, pureMD5 >= 2.1.0.3 && < 2.2
, cereal >= 0.3 && < 0.4
, bytestring >= 0.9.1.4 && < 0.10
, template-haskell
@ -41,6 +40,8 @@ library
, http-types >= 0.6.5 && < 0.7
, unix-compat >= 0.2
, conduit >= 0.0
, crypto-conduit >= 0.1 && < 0.2
, cryptohash >= 0.6.1
exposed-modules: Yesod.Static
ghc-options: -Wall