summaryrefslogtreecommitdiff
path: root/Types
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-07-27 18:52:42 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-07-27 18:56:32 -0400
commitf6e7037c0ccdf646d1ca955c48cece814f5700a4 (patch)
tree035070a47d5bac76e36271507a09aea23ef3ee12 /Types
parent300935948503d671ad91b943787d71dc1f6e421e (diff)
resume interrupted chunked downloads
Leverage the new chunked remotes to automatically resume downloads. Sort of like rsync, although of course not as efficient since this needs to start at a chunk boundry. But, unlike rsync, this method will work for S3, WebDAV, external special remotes, etc, etc. Only directory special remotes so far, but many more soon! This implementation will also properly handle starting a download from one remote, interrupting, and resuming from another one, and so on. (Resuming interrupted chunked uploads is similarly doable, although slightly more expensive.) This commit was sponsored by Thomas Djärv.
Diffstat (limited to 'Types')
-rw-r--r--Types/Key.hs11
1 files changed, 7 insertions, 4 deletions
diff --git a/Types/Key.hs b/Types/Key.hs
index 3015b1e86..154e813ff 100644
--- a/Types/Key.hs
+++ b/Types/Key.hs
@@ -13,8 +13,8 @@ module Types.Key (
stubKey,
key2file,
file2key,
- isChunkKey,
nonChunkKey,
+ chunkKeyOffset,
prop_idempotent_key_encode,
prop_idempotent_key_decode
@@ -49,9 +49,6 @@ stubKey = Key
, keyChunkNum = Nothing
}
-isChunkKey :: Key -> Bool
-isChunkKey k = isJust (keyChunkSize k) && isJust (keyChunkNum k)
-
-- Gets the parent of a chunk key.
nonChunkKey :: Key -> Key
nonChunkKey k = k
@@ -59,6 +56,12 @@ nonChunkKey k = k
, keyChunkNum = Nothing
}
+-- Where a chunk key is offset within its parent.
+chunkKeyOffset :: Key -> Maybe Integer
+chunkKeyOffset k = (*)
+ <$> keyChunkSize k
+ <*> (pred <$> keyChunkNum k)
+
fieldSep :: Char
fieldSep = '-'