Skip to content

feat: return files as bytes from Fetcher.Get with RawFiles - #17

Merged
samgozman merged 1 commit into
mainfrom
feat/fetch-raw-files
Nov 24, 2026
Merged

samgozman merged 1 commit into
mainfrom
feat/fetch-raw-files

Conversation

@samgozman

Copy link
Copy Markdown
Owner

Summary

Adds a RawFiles option to fetch.Fetcher. With it set, Get returns a file that is neither text nor a document, such as an image, as its bytes instead of failing with ErrNotText. A caller that needs such a file no longer has to download it a second time, and the read records one ok attempt instead of an error first.

  • The file is read whole up to MaxDocBytes (32 MiB). A larger one fails with the existing "the file is larger than" error. Pages are still cut at MaxBytes.
  • The body skips the UTF-8 conversion, so binary bytes come back untouched.
  • The server's Content-Type is kept. When the server sends none, the type comes from the bytes.
  • PDFs and office files still come back as Markdown, and a document that fails to read still returns its error.
  • The zero value behaves as before, so the CLI and the MCP server are unchanged.

Tests

  • TestGetRawFiles covers:
    • raw bytes with invalid UTF-8 returned intact, with exactly one ok attempt
    • documents still read as Markdown
    • the server's type kept, and an untyped file typed from its bytes
    • ErrNotText when the option is off
  • TestReadBodyRawFiles covers:
    • a file read past MaxBytes, including an untyped one
    • a file still cut at MaxBytes when the option is off
    • pages still cut at MaxBytes
    • an error past MaxDocBytes
  • make test, make cover-check (92.4%) and make lint pass.

🤖 Generated with Claude Code

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

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.62%. Comparing base (43a9b7b) to head (31abda3).

Files with missing lines Patch % Lines
fetch/fetch.go 85.71% 1 Missing ⚠️
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           
Files with missing lines Coverage Δ
fetch/clients.go 91.35% <100.00%> (+0.10%) ⬆️
fetch/fetch.go 93.93% <85.71%> (+0.11%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@samgozman
samgozman merged commit d6f43c7 into main Nov 24, 2026
6 checks passed
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.

1 participant