on master help sign in
Merge pull request #519 from myfreeweb/master

wai-app-static: use cryptonite instead of cryptohash

commit76e335bb76711fe37f548c39435d4870e8575868 authorMichael Snoyman <michael@snoyman.com> dateMon 14 Mar 2016, 13:01 (11 years ago) parentca06df9467285e
3 files changed+13−15
wai-app-static/WaiAppStatic/Storage/Embedded/Runtime.hs+2−3 wai-app-static/WaiAppStatic/Storage/Filesystem.hs+9−7 wai-app-static/wai-app-static.cabal+2−5
wai-app-static/WaiAppStatic/Storage/Embedded/Runtime.hs+2−3
@@ -16,8 +16,7 @@ import qualified Data.Text as T
1616import Data.Ord
1717import qualified Data.ByteString as S
1818import Crypto.Hash (hash, MD5, Digest)
19−import Data.Byteable (toBytes)
20−import qualified Data.ByteString.Base64 as B64
19+import Data.ByteArray.Encoding
2120import WaiAppStatic.Storage.Filesystem (defaultFileServerSettings)
2221import System.FilePath (isPathSeparator)
2322
@@ -95,4 +94,4 @@ bsToFile name bs = File
9594 }
9695
9796runHash :: ByteString -> ByteString
98−runHash = B64.encode . toBytes . (hash :: S.ByteString -> Digest MD5)
97+runHash = convertToBase Base64 . (hash :: S.ByteString -> Digest MD5)
wai-app-static/WaiAppStatic/Storage/Filesystem.hs+9−7
@@ -1,5 +1,6 @@
11{-# LANGUAGE ScopedTypeVariables #-}
22{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE BangPatterns #-}
34-- | Access files on the filesystem.
45module WaiAppStatic.Storage.Filesystem
56 ( -- * Types
@@ -12,6 +13,7 @@ module WaiAppStatic.Storage.Filesystem
1213
1314import WaiAppStatic.Types
1415import System.FilePath ((</>))
16+import System.IO (withBinaryFile, IOMode(..))
1517import System.Directory (doesFileExist, doesDirectoryExist, getDirectoryContents)
1618import Data.List (foldl')
1719import Control.Monad (forM)
@@ -23,10 +25,9 @@ import WaiAppStatic.Listing
2325import Network.Mime
2426import System.PosixCompat.Files (fileSize, getFileStatus, modificationTime, isRegularFile)
2527import Data.Maybe (catMaybes)
26−import qualified Crypto.Hash.Conduit (hashFile)
27−import Data.Byteable (toBytes)
28−import Crypto.Hash (MD5, Digest)
29−import qualified Data.ByteString.Base64 as B64
28+import Data.ByteArray.Encoding
29+import Crypto.Hash (hashlazy, MD5, Digest)
30+import qualified Data.ByteString.Lazy as BL (hGetContents)
3031import qualified Data.Text as T
3132
3233-- | Construct a new path from a root and some @Pieces@.
@@ -119,9 +120,10 @@ webAppLookup hashFunc prefix pieces =
119120-- | MD5 hash and base64-encode the file contents. Does not check if the file
120121-- exists.
121122hashFile :: FilePath -> IO ByteString
122−hashFile fp = do
123− h <- Crypto.Hash.Conduit.hashFile fp
124− return $ B64.encode $ toBytes (h :: Digest MD5)
123+hashFile fp = withBinaryFile fp ReadMode $ \h -> do
124+ f <- BL.hGetContents h
125+ let !hash = hashlazy f :: Digest MD5
126+ return $ convertToBase Base64 hash
125127
126128hashFileIfExists :: ETagLookup
127129hashFileIfExists fp = do
wai-app-static/wai-app-static.cabal+2−5
@@ -38,9 +38,8 @@ library
3838 , file-embed >= 0.0.3.1
3939 , text >= 0.7
4040 , blaze-builder >= 0.2.1.4
41− , base64-bytestring >= 0.1
42− , byteable
43− , cryptohash >= 0.11
41+ , cryptonite >= 0.6
42+ , memory >= 0.7
4443 , http-date
4544 , blaze-html >= 0.5
4645 , blaze-markup >= 0.5.1
@@ -52,8 +51,6 @@ library
5251 , wai-extra >= 3.0 && < 3.1
5352 , optparse-applicative >= 0.7
5453 , warp >= 3.0.11 && < 3.3
55− -- Used exclusively for hashFile function
56− , cryptohash-conduit
5754
5855 exposed-modules: Network.Wai.Application.Static
5956 WaiAppStatic.Storage.Filesystem