Skip to content

Conversation

@lukekarrys
Copy link

@lukekarrys lukekarrys commented Sep 19, 2025

πŸ”— Linked issue

#1894

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This is one possible way to support binary responses in cachedEventHandler. When stream: true is set on the cache options, the response body will not be read at all and will instead be teed with one stream sent to setItemRaw() and the other returned as the response.

This can be useful for text responses as well when proxying (such as large JSON data) because the response does not need to be read into memory. It can be streamed directly to the client while writing to the cache does not block the response.

When using the stream: true option it will require special handling of the stream in the setItemRaw method of any storage adapter. So I think this is an advanced use-case and doesn't automatically fix #1894.

I experimented with another fix that would use res.arrayBuffer() and convert it to an Uint8Array so the response could still be serialized as JSON. But for my use-case (tar files that were potentially 100s of MB) it was too slow. I'd be happy to amend this PR to support that as well.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@vercel
Copy link

vercel bot commented Sep 19, 2025

@lukekarrys is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

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.

Caching fails when returning a Buffer (PNG image)

1 participant