Skip to content

getArchiveLink() doesn't get the link #391

Open
@filiph

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.

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy