summaryrefslogtreecommitdiff
path: root/lib/SlackBuilder/Download.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2024-03-17 11:00:13 +0100
committerEugen Wissner <belka@caraus.de>2024-03-17 11:00:13 +0100
commit3d81917627188cdbd8809729ecde7e20e21a1a43 (patch)
tree3102cebb2fad7e3d9f51bffdd6429f34ad29f894 /lib/SlackBuilder/Download.hs
parentcd28e6fb901771f91a95d4567c2505212bc29a91 (diff)
downloadslackbuilder-3d81917627188cdbd8809729ecde7e20e21a1a43.tar.gz
Collect hash during creating an archive
Diffstat (limited to 'lib/SlackBuilder/Download.hs')
-rw-r--r--lib/SlackBuilder/Download.hs11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/SlackBuilder/Download.hs b/lib/SlackBuilder/Download.hs
index 23ed3a4..b3723e0 100644
--- a/lib/SlackBuilder/Download.hs
+++ b/lib/SlackBuilder/Download.hs
@@ -2,6 +2,7 @@
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at https://mozilla.org/MPL/2.0/. -}
+-- | Contains routines for downloading, cloning and uploading sources.
module SlackBuilder.Download
( cloneAndUpload
, extractRemote
@@ -10,6 +11,7 @@ module SlackBuilder.Download
, hostedSources
, remoteFileExists
, responseBodySource
+ , sinkFileAndHash
, sinkHash
, updateSlackBuildVersion
, uploadCommand
@@ -66,7 +68,7 @@ import Conduit
, (.|)
, ZipSink(..)
, await
- , sourceFile
+ , sourceFile, MonadResource
)
import Data.Conduit.Tar (untar, FileInfo(..))
import Crypto.Hash (Digest, MD5, hashInit, hashFinalize, hashUpdate)
@@ -244,9 +246,14 @@ download uri packagePath = runReq defaultHttpConfig go
target = packagePath </> fromMaybe downloadFileName attachmentName
digest <- runConduitRes
$ responseBodySource response
- .| getZipSink (ZipSink (sinkFile target) *> ZipSink sinkHash)
+ .| sinkFileAndHash target
pure (targetFileName, digest)
+-- | Writes a file to the destination path and accumulates its MD5 checksum.
+sinkFileAndHash :: MonadResource m => FilePath -> ConduitT ByteString Void m (Digest MD5)
+sinkFileAndHash target = getZipSink
+ $ ZipSink (sinkFile target) *> ZipSink sinkHash
+
-- | Downloads a compressed tar archive and extracts its contents on the fly to
-- a directory.
--