summaryrefslogtreecommitdiff
path: root/Meters.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-11-18 21:48:42 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-11-18 21:50:16 -0400
commit3d6fb239dd88ec7f105b8066b5c5476bb9c2aeec (patch)
treea04c6aeffdbf2ad7756ac5ac6abf704090bf763a /Meters.hs
parent6aa68125b6d476f0ad9372a0f0fbaa5c118e7096 (diff)
refactor
Diffstat (limited to 'Meters.hs')
-rw-r--r--Meters.hs25
1 files changed, 25 insertions, 0 deletions
diff --git a/Meters.hs b/Meters.hs
new file mode 100644
index 000000000..0ea5d3af6
--- /dev/null
+++ b/Meters.hs
@@ -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