update progress meter when sending to p2p remote

This commit was sponsored by Thom May on Patreon.
This commit is contained in:
Joey Hess 2016-12-07 13:37:35 -04:00
parent 7c245b2180
commit 83ea1cec86
No known key found for this signature in database
GPG key ID: C910D9222512E3C7
4 changed files with 24 additions and 28 deletions

View file

@ -85,9 +85,12 @@ streamMeteredFile f meterupdate h = withMeteredFile f meterupdate $ L.hPut h
{- Writes a ByteString to a Handle, updating a meter as it's written. -}
meteredWrite :: MeterUpdate -> Handle -> L.ByteString -> IO ()
meteredWrite meterupdate h = go zeroBytesProcessed . L.toChunks
meteredWrite meterupdate h = void . meteredWrite' meterupdate h
meteredWrite' :: MeterUpdate -> Handle -> L.ByteString -> IO BytesProcessed
meteredWrite' meterupdate h = go zeroBytesProcessed . L.toChunks
where
go _ [] = return ()
go sofar [] = return sofar
go sofar (c:cs) = do
S.hPut h c
let sofar' = addBytesProcessed sofar $ S.length c