Download fetches the selected release archive stream.
( ctx context.Context, slug string, opts registry.DownloadOpts, )
| 232 | |
| 233 | // Download fetches the selected release archive stream. |
| 234 | func (c *Client) Download( |
| 235 | ctx context.Context, |
| 236 | slug string, |
| 237 | opts registry.DownloadOpts, |
| 238 | ) (*registry.DownloadResult, error) { |
| 239 | repo, err := parseRepoSlug(slug) |
| 240 | if err != nil { |
| 241 | return nil, err |
| 242 | } |
| 243 | |
| 244 | release, err := c.fetchRequestedRelease(ctx, repo, strings.TrimSpace(opts.Version)) |
| 245 | if err != nil { |
| 246 | return nil, err |
| 247 | } |
| 248 | |
| 249 | selection, err := selectReleaseDownload(release, strings.TrimSpace(opts.Asset)) |
| 250 | if err != nil { |
| 251 | return nil, fmt.Errorf("github: resolve release asset for %q: %w", repo.full, err) |
| 252 | } |
| 253 | |
| 254 | response, checksum, contentSize, err := c.openDownloadResponse(ctx, repo, release, selection) |
| 255 | if err != nil { |
| 256 | return nil, err |
| 257 | } |
| 258 | |
| 259 | reader, contentType, contentSize, err := finalizeDownloadResponse( |
| 260 | response, |
| 261 | repo.full, |
| 262 | contentSize, |
| 263 | normalizeArchiveSizeLimit(opts.MaxArchiveSize), |
| 264 | ) |
| 265 | if err != nil { |
| 266 | return nil, err |
| 267 | } |
| 268 | |
| 269 | return ®istry.DownloadResult{ |
| 270 | Reader: reader, |
| 271 | Slug: repo.full, |
| 272 | Version: strings.TrimSpace(release.TagName), |
| 273 | ContentSize: contentSize, |
| 274 | Checksum: checksum, |
| 275 | ContentType: contentType, |
| 276 | }, nil |
| 277 | } |
| 278 | |
| 279 | // Close releases any idle HTTP connections held by the client. |
| 280 | func (c *Client) Close() error { |