Skip to content

Commit

Permalink
Remove dependency on cryptonite and memory (#843)
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentRDC authored Apr 15, 2021
1 parent af9e29b commit 122dd42
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 32 deletions.
3 changes: 1 addition & 2 deletions hakyll.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,13 @@ Library
blaze-markup >= 0.5.1 && < 0.9,
bytestring >= 0.9 && < 0.11,
containers >= 0.3 && < 0.7,
cryptonite >= 0.25 && < 0.29,
data-default >= 0.4 && < 0.8,
deepseq >= 1.3 && < 1.5,
directory >= 1.2.7.0 && < 1.4,
file-embed >= 0.0.10.1 && < 0.0.14,
filepath >= 1.0 && < 1.5,
hashable >= 1.0 && < 2,
lrucache >= 1.1.1 && < 1.3,
memory >= 0.14.18 && < 0.16,
mtl >= 1 && < 2.3,
network-uri >= 2.6 && < 2.7,
optparse-applicative >= 0.12 && < 0.17,
Expand Down
29 changes: 3 additions & 26 deletions lib/Hakyll/Core/Store.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,14 @@ module Hakyll.Core.Store


--------------------------------------------------------------------------------
import qualified Data.ByteArray as BA
import qualified Crypto.Hash as CH
import qualified Data.Hashable as DH
import Data.Binary (Binary, decode, encodeFile)
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
import qualified Data.Cache.LRU.IO as Lru
import Data.List (intercalate)
import Data.Maybe (isJust)
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import Data.Typeable (TypeRep, Typeable, cast, typeOf)
import Numeric (showHex)
import System.Directory (createDirectoryIfMissing)
import System.Directory (doesFileExist, removeFile)
import System.Directory (createDirectoryIfMissing, doesFileExist, removeFile)
import System.FilePath ((</>))
import System.IO (IOMode (..), hClose, openFile)
import System.IO.Error (catchIOError, ioeSetFileName,
Expand Down Expand Up @@ -194,21 +188,4 @@ deleteFile = (`catchIOError` \_ -> return ()) . removeFile
--------------------------------------------------------------------------------
-- | Mostly meant for internal usage
hash :: [String] -> String
hash = toHex . B.unpack . hashMD5 . T.encodeUtf8 . T.pack . intercalate "/"
where
toHex [] = ""
toHex (x : xs) | x < 16 = '0' : showHex x (toHex xs)
| otherwise = showHex x (toHex xs)


--------------------------------------------------------------------------------
-- | Hash by MD5
hashMD5 :: B.ByteString -> B.ByteString
hashMD5 x =
let
digest :: CH.Digest CH.MD5
digest = CH.hash x
bytes :: B.ByteString
bytes = BA.convert digest
in
bytes
hash = show . DH.hash . intercalate "/"
6 changes: 2 additions & 4 deletions test.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{-# LANGUAGE BangPatterns #-}
import Control.Monad (forM)
import qualified Crypto.Hash.SHA256 as SHA256
import qualified Data.ByteString.Base16 as Base16
import qualified Data.ByteString.Char8 as BS8
import qualified Data.ByteString.Lazy as BSL
import qualified Data.Hashable as DH
import Data.Map (Map)
import qualified Data.Map as Map
import Hakyll
Expand All @@ -20,9 +20,7 @@ mkFileHashes dir = do
return (fromFilePath path1, h)
where
hash :: FilePath -> IO String
hash fp = do
!h <- SHA256.hashlazy <$> BSL.readFile fp
return $! BS8.unpack $! Base16.encode h
hash fp = (show . DH.hash) <$> BSL.readFile fp

main :: IO ()
main = hakyll $ do
Expand Down

0 comments on commit 122dd42

Please sign in to comment.