Skip to content

Commit

Permalink
Go for minimal diff
Browse files Browse the repository at this point in the history
  • Loading branch information
philderbeast committed Jan 23, 2024
1 parent 6b93ec9 commit c0ad47c
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions precompute-fileinfo/src/Main.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{-# LANGUAGE ScopedTypeVariables #-}

module Main where

import Control.Concurrent
Expand Down Expand Up @@ -169,17 +167,14 @@ writeMap fp hashes = withFile fp WriteMode $ \h ->
readMap :: FilePath -> IO (Map MD5 (SHA256, Length))
readMap fp =
withFile fp ReadMode $ \h -> do
hashes <- mapFromParseEntry . lines <$> hGetContents h
hashes <- Map.fromList . map parseEntry . lines <$> hGetContents h
evaluate $ rnf hashes
return hashes
where
mapFromParseEntry :: [String] -> Map MD5 (SHA256, Length)
mapFromParseEntry mapLines = Map.fromList
[ case ws of
[md5, sha256, len] -> (md5, (sha256, read len))
_ -> (unwords ws, undefined)
| ws <- words <$> mapLines
]
parseEntry :: String -> (MD5, (SHA256, Length))
parseEntry line = case words line of
[md5, sha256, len] -> (md5, (sha256, read len))
_ -> error $ "failed: parseEntry " ++ show line

{-------------------------------------------------------------------------------
Auxiliary
Expand Down

0 comments on commit c0ad47c

Please sign in to comment.