You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, when working with the Fetch API, converting response data to base64 encoding requires multiple steps and introduces complexity, especially when handling binary data. Developers often need to:
Read the response as a blob or array buffer
Convert it to base64 using additional utilities
Handle potential encoding issues
This process is error-prone and requires additional code that could be standardized.
What solutions exist today?
Existing Solutions
Currently, developers typically handle this in one of these ways:
Standardization: Consistent behavior across browsers
Error handling: Built-in handling of encoding edge cases
Compatibility
The method name base64() is not currently used in the Response prototype, making it safe to add. The method would return a Promise to maintain consistency with other Response body reading methods.
Additional Considerations
Security
The method should respect same-origin policies
Large responses should be handled efficiently to prevent memory issues
Consider adding optional parameters for handling different encodings
Edge Cases
Handle empty responses
Consider adding options for URL-safe base64 encoding
Define behavior for streaming responses
Performance Impact
Native implementation can optimize the conversion process
Consider chunked processing for large responses
Potential for WebAssembly acceleration
Anything else?
Open Questions
Should there be a size limit for automatic base64 conversion?
Should streaming be supported for large responses?
Should there be options for different base64 variants (standard, URL-safe)?
What problem are you trying to solve?
Problem Statement
Currently, when working with the Fetch API, converting response data to base64 encoding requires multiple steps and introduces complexity, especially when handling binary data. Developers often need to:
This process is error-prone and requires additional code that could be standardized.
What solutions exist today?
Existing Solutions
Currently, developers typically handle this in one of these ways:
Both approaches have drawbacks:
How would you solve it?
Proposed Solution
Add a new method
base64()
to the Response prototype:Example usage:
Implementation Details
The method would:
Benefits
Compatibility
The method name
base64()
is not currently used in the Response prototype, making it safe to add. The method would return a Promise to maintain consistency with other Response body reading methods.Additional Considerations
Security
Edge Cases
Performance Impact
Anything else?
Open Questions
Originally posted by @hemanth in whatwg/fetch#1800
The text was updated successfully, but these errors were encountered: