You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add documentation and comprehensive tests for resumable downloads
Add resumable download example and update gitignore
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
This example demonstrates how to use the resumable download feature to fetch specific byte ranges from container registry layers using HTTP range requests.
4
+
5
+
## Usage
6
+
7
+
```bash
8
+
go run main.go <digest-ref><start-byte><end-byte>
9
+
```
10
+
11
+
## Example
12
+
13
+
```bash
14
+
# Fetch the first 1024 bytes from a layer
15
+
go run main.go gcr.io/my-repo/my-image@sha256:abc123... 0 1023
16
+
17
+
# Resume a download starting from byte 1024
18
+
go run main.go gcr.io/my-repo/my-image@sha256:abc123... 1024 2047
19
+
```
20
+
21
+
## Use Cases
22
+
23
+
-**Resumable Downloads**: If a download is interrupted, you can resume from where it left off
24
+
-**Partial Content Access**: Access only the portion of a layer you need
25
+
-**Progressive Loading**: Load content incrementally for better user experience
26
+
-**Bandwidth Optimization**: Download only the required portions of large layers
27
+
28
+
## Notes
29
+
30
+
- Range requests require a digest reference (not a tag)
31
+
- The byte offsets are inclusive (start and end bytes are both included)
32
+
- Hash verification is not performed on partial content
33
+
- Not all registries support range requests (though most modern ones do)
Copy file name to clipboardExpand all lines: pkg/v1/remote/README.md
+40Lines changed: 40 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,6 +34,46 @@ func main() {
34
34
}
35
35
```
36
36
37
+
### Resumable Downloads
38
+
39
+
The `remote` package supports resumable downloads via HTTP range requests. This is useful for downloading large layers or for resuming interrupted downloads:
// Download a specific byte range (bytes 1000-9999)
60
+
// This is useful for resuming downloads or fetching specific portions
61
+
rc, err:= remote.LayerRange(ref, 1000, 9999)
62
+
if err != nil {
63
+
panic(err)
64
+
}
65
+
defer rc.Close()
66
+
67
+
// Copy the range to a file or process it
68
+
_, err = io.Copy(os.Stdout, rc)
69
+
if err != nil {
70
+
panic(err)
71
+
}
72
+
}
73
+
```
74
+
75
+
Note: When using range requests, hash verification is not performed on the partial content. To verify the integrity of the full blob, download it completely using `remote.Layer()` instead.
0 commit comments