restore-file - Support binary files#9120
Conversation
|
Tests:
|
|
@copilot take a look. Don't commit any changes, just explain what could be the issue and how it can be fixed |
Root cause: In How to fix: The
This would handle both binary files and large files (up to 100MB) correctly, since the raw binary data never goes through text decoding. (Note: the empty/0-byte file issue with |
@fregante do we need that option? I think |
|
Limiting the whole feature to <1MB is definitely a downgrade, so that's out of the question. A common file I restore is package-lock.json, which is too often very large (monorepos and such) As for the binary option, it would be ok as long as we don't have to manually toggle between two fetching modes in this feature. I think that would introduce many points of failure. What do you think? |
|
|
This comment was marked as resolved.
This comment was marked as resolved.
|
Same questions here as the other PR, they're actually more relevant here. |
Ready to be merged
Other than 100mb file size limit - none
Yes |
| if (base64) { | ||
| const arrayBuffer = await response.arrayBuffer(); | ||
| const content = uint8ArrayToBase64(new Uint8Array(arrayBuffer)); | ||
| apiResponse = {content}; |
There was a problem hiding this comment.
Base64 is not a useful output for our helper, I think it's best to return the lower-level type instead, Promise<ArrayBuffer>?
Base64 is only useful here because the POST API later requires this format.
Since we're here, are we sure there isn't an even better way to POST the bytes? Would be fantastic if we could pass the raw Response stream straight to the POST api.
There was a problem hiding this comment.
Promise<ArrayBuffer>
And what we're gonna do with it?
are we sure there isn't an even better way to POST the bytes?
I'm sure:
https://docs.github.com/en/graphql/reference/input-objects#filechanges
https://docs.github.com/en/rest/git/blobs?apiVersion=2026-03-10#create-a-blob
|
It's ok if you merge this and possibly revisit the helper later. That part might require larger codebase changes. |
This comment was marked as resolved.
This comment was marked as resolved.
|
Thanks for this! I look forward to using it in a tagged release! |

Resolves #8110
Test URLs
https://github.com/refined-github/sandbox/pull/128/changes#diff-e31df6ca67b7e6390cb4e019f9a614ec44caafec9956f6b46eb2392846213809
Screenshot