Repository navigation
feat: return files as bytes from Fetcher.Get with RawFiles - #17
Merged
Merged
Conversation
A program that imports the fetch package and needs an image had to catch ErrNotText and download the file again with its own client, and every such read logged a failed attempt first. With RawFiles set, Get returns a file that is neither text nor a document as its bytes, up to MaxDocBytes, with one ok attempt. The body skips the UTF-8 conversion, keeps the server's content type (or the sniffed one when the server sends none), and PDFs and office files still come back as Markdown. The zero value behaves as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #17 +/- ##
=======================================
Coverage 92.61% 92.62%
=======================================
Files 43 43
Lines 3929 3933 +4
=======================================
+ Hits 3639 3643 +4
Misses 288 288
Partials 2 2
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
RawFilesoption tofetch.Fetcher. With it set,Getreturns a file that is neither text nor a document, such as an image, as its bytes instead of failing withErrNotText. A caller that needs such a file no longer has to download it a second time, and the read records oneokattempt instead of an error first.MaxDocBytes(32 MiB). A larger one fails with the existing "the file is larger than" error. Pages are still cut atMaxBytes.Content-Typeis kept. When the server sends none, the type comes from the bytes.Tests
TestGetRawFilescovers:okattemptErrNotTextwhen the option is offTestReadBodyRawFilescovers:MaxBytes, including an untyped oneMaxByteswhen the option is offMaxBytesMaxDocBytesmake test,make cover-check(92.4%) andmake lintpass.🤖 Generated with Claude Code