summaryrefslogtreecommitdiff
path: root/Remote/Helper
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-11-18 18:27:53 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-11-18 18:27:53 -0400
commitac71b499ac6d53408cfce19a1ddd00bfa4b2645f (patch)
tree8edf701de6ee4a7fae691743e87ac1f5f6e78b25 /Remote/Helper
parent677aab525a7023642f4b2e9d96db3c3481e8f0b1 (diff)
simplify
Diffstat (limited to 'Remote/Helper')
-rw-r--r--Remote/Helper/Chunked.hs34
1 files changed, 17 insertions, 17 deletions
diff --git a/Remote/Helper/Chunked.hs b/Remote/Helper/Chunked.hs
index dd6e3eb0d..f6a4308b3 100644
--- a/Remote/Helper/Chunked.hs
+++ b/Remote/Helper/Chunked.hs
@@ -125,21 +125,21 @@ storeChunked chunksize dests storer content =
- after each chunk of the L.ByteString, typically every 64 kb or so. -}
meteredWriteFile :: MeterUpdate -> FilePath -> L.ByteString -> IO ()
meteredWriteFile meterupdate dest b =
- meteredWriteFileChunks meterupdate dest (L.toChunks b) feeder
+ meteredWriteFileChunks meterupdate dest [b] return
+
+{- Writes a series of major chunks to a file. The feeder is called to get
+ - each major chunk. Then each chunk of the L.ByteString is written,
+ - with the meter updated after each chunk. -}
+meteredWriteFileChunks :: MeterUpdate -> FilePath -> [v] -> (v -> IO L.ByteString) -> IO ()
+meteredWriteFileChunks meterupdate dest chunks feeder =
+ E.bracket (openFile dest WriteMode) hClose (feed chunks [])
where
- feeder chunks = return ([], chunks)
-
-{- Writes a series of S.ByteString chunks to a file, updating a progress
- - meter after each chunk. The feeder is called to get more chunks. -}
-meteredWriteFileChunks :: MeterUpdate -> FilePath -> s -> (s -> IO (s, [S.ByteString])) -> IO ()
-meteredWriteFileChunks meterupdate dest startstate feeder =
- E.bracket (openFile dest WriteMode) hClose (feed startstate [])
- where
- feed state [] h = do
- (state', cs) <- feeder state
- unless (null cs) $
- feed state' cs h
- feed state (c:cs) h = do
- S.hPut h c
- meterupdate $ toInteger $ S.length c
- feed state cs h
+ feed [] [] _ = noop
+ feed (c:cs) [] h = do
+ bs <- L.toChunks <$> feeder c
+ unless (null bs) $
+ feed cs bs h
+ feed cs (b:bs) h = do
+ S.hPut h b
+ meterupdate $ toInteger $ S.length b
+ feed cs bs h