Skip to content

getArchiveLink() doesn't get the link #391

Description

@filiph

When calling:

var archiveLink = await github.repositories
    .getArchiveLink(repo, defaultRef, format: 'zipball');

I expect to get the link (String). Instead, the method errors out.

Unhandled exception:
GitHub Error: 
#0      GitHub.handleStatusCode (package:github/src/common/github.dart:486:5)
#1      GitHub.request (package:github/src/common/github.dart:422:7)
<asynchronous suspension>
#2      RepositoriesService.getArchiveLink (package:github/src/common/repos_service.dart:678:22)
<asynchronous suspension>
#3      main (file:///Users/filiph/dev/sample_downloader/bin/sample_downloader.dart:166:21)
<asynchronous suspension>

It turns out that the GitHub API just redirects (?) to the link of the archive, so the call above actually starts downloading the archive itself. The error is because package:github is expecting a JSON response, and so handleStatusCode() throws (the status code is actually 200, it just isn't a JSON).

I'm not sure whether this is an API change on the part of GitHub or what it is.

Expected behavior:
If possible, I'd like to get the URL at which to download the zip/tar archive with a normal (non-authorized) HTTP call, as suggested in the docs. For example, I'd like to pipe the streamed response directly into unzip, or into a temporary file on disk.

If that's not possible, and the only way to access the archive is through an authorized call, then have an API for that, and remove the getArchiveLink() method.

Workaround:

var response = await github.request(
    'GET',
    '/repos/${repo.fullName}/zipball/$defaultRef',
);

This is okay, but breaks encapsulation. Also, it downloads the whole huge file into memory.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions