summaryrefslogtreecommitdiff
path: root/Remote/Helper
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-11-03 19:50:33 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-11-03 19:50:33 -0400
commit76c97f4ea90293b04a416368c107d1cc19cc381b (patch)
tree2bd234bfd9a8816e686af85f233114f9c7b8c9a0 /Remote/Helper
parente6cac7f24606d57d2a70a4ff96c4557ade4a0b3a (diff)
WIP 2
Diffstat (limited to 'Remote/Helper')
-rw-r--r--Remote/Helper/Http.hs13
1 files changed, 8 insertions, 5 deletions
diff --git a/Remote/Helper/Http.hs b/Remote/Helper/Http.hs
index 4088854ff..cb3af335a 100644
--- a/Remote/Helper/Http.hs
+++ b/Remote/Helper/Http.hs
@@ -11,7 +11,7 @@ import Common.Annex
import Types.StoreRetrieve
import Utility.Metered
import Remote.Helper.Special
-import Network.HTTP.Client (RequestBody(..), Response, responseStatus, responseBody, BodyReader)
+import Network.HTTP.Client (RequestBody(..), Response, responseStatus, responseBody, BodyReader, NeedsPopper)
import Network.HTTP.Types
import qualified Data.ByteString.Lazy as L
@@ -31,11 +31,14 @@ httpStorer a = fileStorer $ \k f m -> a k =<< liftIO (httpBodyStorer f m)
httpBodyStorer :: FilePath -> MeterUpdate -> IO RequestBody
httpBodyStorer src m = do
size <- fromIntegral . fileSize <$> getFileStatus src :: IO Integer
- let streamer sink = withMeteredFile src m $ \b -> do
- mvar <- newMVar $ L.toChunks b
- let getnextchunk = modifyMVar mvar $ pure . pop
- sink getnextchunk
+ let streamer sink = withMeteredFile src m $ \b -> mkPopper b sink
return $ RequestBodyStream (fromInteger size) streamer
+
+mkPopper :: L.ByteString -> NeedsPopper () -> IO ()
+mkPopper b sink = do
+ mvar <- newMVar $ L.toChunks b
+ let getnextchunk = modifyMVar mvar $ pure . pop
+ sink getnextchunk
where
pop [] = ([], S.empty)
pop (c:cs) = (cs, c)