Skip to content

Allow use_github_file() to work with non-text files - #2173

Open
ateucher wants to merge 17 commits into
mainfrom
general-github-file
Open

ateucher wants to merge 17 commits into
mainfrom
general-github-file

Conversation

@ateucher

@ateucher ateucher commented Sep 19, 2025 •

Copy link
Copy Markdown
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.

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
Comment thread tests/testthat/test-use_github_file.R Resolved
Replace `mime::guess_type()` with a NUL-byte check (same as used by `grep -I` and git) in new `is_binary_file()` helper. This drops the `mime` dependency and is more robust (previously detected yaml as binary)
This matches the prompting behaviour for text files in write_over(). Otherwise binary files hit a raw `file_copy()` error when the destination already existed.
@ateucher

ateucher commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator Author

Hi @jennybc, I got Posit Assitant to help me clean this up and make it more robust, and also avoid adding mime as a new dependency.

  • Check file content, not extension to find binaries: is_binary_file() checks for NUL-bytes (same as grep -I/git). This fixes YAML/JSON files (application/* MIME types) and extensionless files being misclassified as binary, and drops the mime dependency.
  • Fixed get_release_news(): Moved read_utf8() inside the tryCatch.
  • Binary files now get same treatment overwrite as text in write_file(), used can_overwrite().
  • Added tests for the detection helper and binary overwrite behavior, a NEWS bullet, and skip_if_offline() on the download test.

@ateucher
ateucher requested a review from jennybc September 17, 2026 16:27

This branch has not been deployed

No deployments
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