diff --git a/wai-app-static/WaiAppStatic/Storage/Embedded/Runtime.hs b/wai-app-static/WaiAppStatic/Storage/Embedded/Runtime.hs index 2f50c7e13..f25719c87 100644 --- a/wai-app-static/WaiAppStatic/Storage/Embedded/Runtime.hs +++ b/wai-app-static/WaiAppStatic/Storage/Embedded/Runtime.hs @@ -16,8 +16,7 @@ import qualified Data.Text as T import Data.Ord import qualified Data.ByteString as S import Crypto.Hash (hash, MD5, Digest) -import Data.Byteable (toBytes) -import qualified Data.ByteString.Base64 as B64 +import Data.ByteArray.Encoding import WaiAppStatic.Storage.Filesystem (defaultFileServerSettings) import System.FilePath (isPathSeparator) @@ -95,4 +94,4 @@ bsToFile name bs = File } runHash :: ByteString -> ByteString -runHash = B64.encode . toBytes . (hash :: S.ByteString -> Digest MD5) +runHash = convertToBase Base64 . (hash :: S.ByteString -> Digest MD5) diff --git a/wai-app-static/WaiAppStatic/Storage/Filesystem.hs b/wai-app-static/WaiAppStatic/Storage/Filesystem.hs index 76f31425a..665c409da 100644 --- a/wai-app-static/WaiAppStatic/Storage/Filesystem.hs +++ b/wai-app-static/WaiAppStatic/Storage/Filesystem.hs @@ -1,5 +1,6 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE BangPatterns #-} -- | Access files on the filesystem. module WaiAppStatic.Storage.Filesystem ( -- * Types @@ -12,6 +13,7 @@ module WaiAppStatic.Storage.Filesystem import WaiAppStatic.Types import System.FilePath (()) +import System.IO (withBinaryFile, IOMode(..)) import System.Directory (doesFileExist, doesDirectoryExist, getDirectoryContents) import Data.List (foldl') import Control.Monad (forM) @@ -23,10 +25,9 @@ import WaiAppStatic.Listing import Network.Mime import System.PosixCompat.Files (fileSize, getFileStatus, modificationTime, isRegularFile) import Data.Maybe (catMaybes) -import qualified Crypto.Hash.Conduit (hashFile) -import Data.Byteable (toBytes) -import Crypto.Hash (MD5, Digest) -import qualified Data.ByteString.Base64 as B64 +import Data.ByteArray.Encoding +import Crypto.Hash (hashlazy, MD5, Digest) +import qualified Data.ByteString.Lazy as BL (hGetContents) import qualified Data.Text as T -- | Construct a new path from a root and some @Pieces@. @@ -119,9 +120,10 @@ webAppLookup hashFunc prefix pieces = -- | MD5 hash and base64-encode the file contents. Does not check if the file -- exists. hashFile :: FilePath -> IO ByteString -hashFile fp = do - h <- Crypto.Hash.Conduit.hashFile fp - return $ B64.encode $ toBytes (h :: Digest MD5) +hashFile fp = withBinaryFile fp ReadMode $ \h -> do + f <- BL.hGetContents h + let !hash = hashlazy f :: Digest MD5 + return $ convertToBase Base64 hash hashFileIfExists :: ETagLookup hashFileIfExists fp = do diff --git a/wai-app-static/wai-app-static.cabal b/wai-app-static/wai-app-static.cabal index 7791bfc90..a538df94c 100644 --- a/wai-app-static/wai-app-static.cabal +++ b/wai-app-static/wai-app-static.cabal @@ -38,9 +38,8 @@ library , file-embed >= 0.0.3.1 , text >= 0.7 , blaze-builder >= 0.2.1.4 - , base64-bytestring >= 0.1 - , byteable - , cryptohash >= 0.11 + , cryptonite >= 0.6 + , memory >= 0.7 , http-date , blaze-html >= 0.5 , blaze-markup >= 0.5.1 @@ -52,8 +51,6 @@ library , wai-extra >= 3.0 && < 3.1 , optparse-applicative >= 0.7 , warp >= 3.0.11 && < 3.3 - -- Used exclusively for hashFile function - , cryptohash-conduit exposed-modules: Network.Wai.Application.Static WaiAppStatic.Storage.Filesystem