From e0f51b0c90ffb7593ec7d31de625659e4692197b Mon Sep 17 00:00:00 2001 From: raichoo Date: Thu, 18 Oct 2018 15:33:53 +0200 Subject: [PATCH] fix space leak There was a space leak when copmuting the CRC for the file. This basically retained file data so streaming did not happen in constant memory anymore. --- Codec/Archive/Zip/Conduit/Internal.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Codec/Archive/Zip/Conduit/Internal.hs b/Codec/Archive/Zip/Conduit/Internal.hs index ce8722e..98fddb7 100644 --- a/Codec/Archive/Zip/Conduit/Internal.hs +++ b/Codec/Archive/Zip/Conduit/Internal.hs @@ -1,4 +1,5 @@ {-# LANGUAGE CPP #-} +{-# LANGUAGE BangPatterns #-} module Codec.Archive.Zip.Conduit.Internal ( osVersion, zipVersion , zipError @@ -42,14 +43,14 @@ idConduit :: Monad m => C.ConduitM a a m () idConduit = C.awaitForever C.yield passthroughFold :: Monad m => (a -> b -> a) -> a -> C.ConduitM b b m a -passthroughFold f z = C.await >>= maybe +passthroughFold f !z = C.await >>= maybe (return z) (\x -> do C.yield x passthroughFold f (f z x)) sizeCRC :: Monad m => C.ConduitM BS.ByteString BS.ByteString m (Word64, Word32) -sizeCRC = passthroughFold (\(l, c) b -> (l + fromIntegral (BS.length b), crc32Update c b)) (0, 0) +sizeCRC = passthroughFold (\(!l, !c) b -> (l + fromIntegral (BS.length b), crc32Update c b)) (0, 0) sizeC :: Monad m => C.ConduitM BS.ByteString BS.ByteString m Word64 sizeC = passthroughFold (\l b -> l + fromIntegral (BS.length b)) 0 -- fst <$> sizeCRC