Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(FormData/Serializer): Early fix for supporting async blob source #11050

Merged
merged 4 commits into from
Jun 22, 2021

Conversation

jimmywarting
Copy link
Contributor

@jimmywarting jimmywarting commented Jun 19, 2021

This new FormData Serializer takes a FormData and converts it into a new Blob with other preexisting Blob parts

The benefits

  • Less code
  • Don't need to calculate the byte length (Content-Length) - you get it from the new blob instead
  • Don't have to read the content of the File entries or keeping any of the File entry content in memory until it's necessary to read them after blob.stream() is called, hence more RAM friendly
  • Still synchronous
    • Good for when you eg have to clone a Response new Response(new FormData()).clone()? but why would you? have have no idea, still a valid case?
  • partially solves a blocker of async blob sources (refactor: asynchronous blob backing store #10969)

Other considerations/possible solutions:

Returning a ReadableStream or async iterator... Converting it to a blob seems to be the most easiest... Then fetch can just treat it as a any other blob and don't do any special if-that-then-do-this logic
I have used this formdata-to-blob technique in my formdata-polyfill for years by converting it into a blob since IE9 was a thing in the past


The old Serializer did read the content from File Entries using _byteSequence. That is no longer going to be supported once we have async blob sources that can originate from the filesystem and don't hold the data in memory

@jimmywarting jimmywarting changed the title New FormData Serializer refactor(FormData/Serializer): Fix for supporting async blob source Jun 20, 2021
@jimmywarting jimmywarting changed the title refactor(FormData/Serializer): Fix for supporting async blob source refactor(FormData/Serializer): Early fix for supporting async blob source Jun 20, 2021
@lucacasonato lucacasonato self-requested a review June 20, 2021 09:57
Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks. Nice simplification.

@lucacasonato lucacasonato merged commit 0a2ced5 into denoland:main Jun 22, 2021
@jimmywarting jimmywarting deleted the serialize_formdata branch June 22, 2021 12:16
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.

2 participants