refactor
This commit is contained in:
parent
afa2f9c967
commit
e2b7fc1ebd
7 changed files with 45 additions and 19 deletions
25
Meters.hs
Normal file
25
Meters.hs
Normal file
|
@ -0,0 +1,25 @@
|
|||
{- git-annex meters
|
||||
-
|
||||
- Copyright 2012 Joey Hess <joey@kitenet.net>
|
||||
-
|
||||
- Licensed under the GNU GPL version 3 or higher.
|
||||
-}
|
||||
|
||||
module Meters where
|
||||
|
||||
import Common
|
||||
import Types.Meters
|
||||
import Utility.Observed
|
||||
|
||||
import qualified Data.ByteString.Lazy as L
|
||||
|
||||
{- Sends the content of a file to an action, updating the meter as it's
|
||||
- consumed. -}
|
||||
withMeteredFile :: FilePath -> MeterUpdate -> (L.ByteString -> IO a) -> IO a
|
||||
withMeteredFile f meterupdate a = withBinaryFile f ReadMode $ \h ->
|
||||
hGetContentsObserved h (meterupdate . toInteger) >>= a
|
||||
|
||||
{- 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
|
Loading…
Add table
Add a link
Reference in a new issue