packages feed

sha-streams 0.1.0 → 0.1.1

raw patch · 3 files changed

+20/−11 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ System.IO.Streams.SHA: Pair :: !a -> !b -> Pair a b
+ System.IO.Streams.SHA: data Pair a b
+ System.IO.Streams.SHA: uncurry' :: (a -> b -> c) -> Pair a b -> c

Files

System/IO/Streams/SHA.hs view
@@ -58,14 +58,20 @@ checkedSha512Input' :: String -> InputStream ByteString -> IO (InputStream ByteString) checkedSha512Input' = checkedShaInput sha512Incremental completeSha512Incremental +-- | Strict pairs.+data Pair a b = Pair !a !b++uncurry' :: (a -> b -> c) -> Pair a b -> c+uncurry' f (Pair a b) = f a b+ -- | Inspired by `S.countInput`. The returned IO action can be run only -- when the input stream is exhausted, otherwise an error occurs. shaInput :: Decoder a -> (Decoder a -> Int -> Digest a)   -> InputStream ByteString -> IO (InputStream ByteString, IO (Digest a)) shaInput increment end is = do-  ref <- newIORef (increment, 0)+  ref <- newIORef $ Pair increment 0   is' <- S.makeInputStream $ prod ref-  return $! (is', readIORef ref >>= uncurry complete)+  return $! (is', readIORef ref >>= uncurry' complete)    where @@ -73,18 +79,18 @@     mbs <- S.read is     maybe       (return Nothing)-      (\bs -> (modifyRef ref (uncurry $ modify bs)) >> (return $! Just bs))+      (\bs -> (modifyRef ref (uncurry' $ modify bs)) >> (return $! Just bs))       mbs    complete decoder c = return $! end decoder c-  modify bs decoder c = (pushChunk decoder bs, c + (fromIntegral $ C.length bs))+  modify bs decoder c = Pair (pushChunk decoder bs) (c + (fromIntegral $ C.length bs))  -- | This returns an input stream exactly as the one being wrapped, but throws -- an error if the computed SHA hash does not match the one given. checkedShaInput :: Decoder a -> (Decoder a -> Int -> Digest a)   -> String -> InputStream ByteString -> IO (InputStream ByteString) checkedShaInput increment end digest is = do-  ref <- newIORef (increment, 0)+  ref <- newIORef $ Pair increment 0   is' <- S.makeInputStream $ prod ref   return $! is' @@ -94,15 +100,15 @@     mbs <- S.read is     maybe       (do r <- readIORef ref-          digest' <- uncurry complete r+          digest' <- uncurry' complete r           if digest == showDigest digest'             then return Nothing             else throwIO UnmatchedSHAException)-      (\bs -> (modifyRef ref (uncurry $ modify bs)) >> (return $! Just bs))+      (\bs -> (modifyRef ref (uncurry' $ modify bs)) >> (return $! Just bs))       mbs    complete decoder c = return $! end decoder c-  modify bs decoder c = (pushChunk decoder bs, c + (fromIntegral $ C.length bs))+  modify bs decoder c = Pair (pushChunk decoder bs) (c + (fromIntegral $ C.length bs))  -- | Taken from System.IO.Streams.ByteString. {-# INLINE modifyRef #-}
bin/sha-streams.hs view
@@ -1,5 +1,6 @@ module Main (main) where +import System.Environment (getArgs) import qualified System.IO.Streams as S  import Data.Digest.Pure.SHA@@ -7,7 +8,8 @@  main :: IO () main = do-  d1 <- S.withFileAsInput "bin/sha-streams.hs" $ \is -> do+  [filename] <- getArgs+  d1 <- S.withFileAsInput filename $ \is -> do     (is1, getSha1) <- sha1Input is     (is224, getSha224) <- sha224Input is1     (is256, getSha256) <- sha256Input is224@@ -22,7 +24,8 @@     getSha512 >>= putStrLn . showDigest     return d1 -  -- This must throw an UnmatchedSHAException.+  -- This must throw an UnmatchedSHAException (unless `filename` above is+  -- "System/IO/Streams/SHA.hs").   S.withFileAsInput "System/IO/Streams/SHA.hs" $ \is -> do     (is1, _) <- sha1Input is     is1' <- checkedSha1Input d1 is1
sha-streams.cabal view
@@ -1,5 +1,5 @@ name:                sha-streams-version:             0.1.0+version:             0.1.1 Cabal-Version:       >= 1.8 synopsis:            SHA hashes for io-streams. description:         SHA hashes for io-streams.