Skip to content

Conversation

ateucher
Copy link
Collaborator

Since text files are read with read_utf8() and written to the final destination with write_over(), I changed read_github_file() to get_github_file() and instead of returning the text lines, it returns a path to a temp file, which requires using read_utf8() in places it was used before.

This adds {mime} as a new dependency to detect the mimetype so we can branch on that: copy the file if it is binary, and read+write the lines if it is text.

Happy to take a different approach if you have a better way!

I added one small test, which I can expand if this direction is ok.

Fixes #1782.

Add mime dependency and update use_github_file() to handle both text and binary files by detecting MIME type.

Fixes #1782
Need to read_utf() now since get_github_file() returns a path
test_that("use_github_file works with non-text files", {
create_local_project()
use_github_file(
"https://github.com/r-lib/usethis/blob/main/man/figures/logo.png",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is probably stable, but I can put a small png in tests/testthat/ if that would be better?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make use_github_file() more general
1 participant