diff options
author | Joey Hess <joey@kitenet.net> | 2012-11-18 22:49:07 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-11-18 22:49:07 -0400 |
commit | 7e9c2f1ef320e01320560eb2e3d92e1bc1bae0aa (patch) | |
tree | 88a9aada9729c9237d786f12548cc138f9574d3c /Meters.hs | |
parent | 8ffd06e588011fd26cd258530b0c05b42b484a0a (diff) |
S3: Added progress display for uploading and downloading.
Diffstat (limited to 'Meters.hs')
-rw-r--r-- | Meters.hs | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -12,6 +12,7 @@ import Types.Meters import Utility.Observed import qualified Data.ByteString.Lazy as L +import qualified Data.ByteString as S {- Sends the content of a file to an action, updating the meter as it's - consumed. -} @@ -21,5 +22,19 @@ withMeteredFile f meterupdate a = withBinaryFile f ReadMode $ \h -> {- Sends the content of a file to a Handle, updating the meter as it's - written. -} -sendMeteredFile :: FilePath -> MeterUpdate -> Handle -> IO () -sendMeteredFile f meterupdate h = withMeteredFile f meterupdate $ L.hPut h +streamMeteredFile :: FilePath -> MeterUpdate -> Handle -> IO () +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 . L.toChunks + where + go [] = return () + go (c:cs) = do + S.hPut h c + meterupdate $ toInteger $ S.length c + go cs + +meteredWriteFile :: MeterUpdate -> FilePath -> L.ByteString -> IO () +meteredWriteFile meterupdate f b = withBinaryFile f WriteMode $ \h -> + meteredWrite meterupdate h b |