feat(http/unstable): FormData Decoder/Encoder Streams#6928
feat(http/unstable): FormData Decoder/Encoder Streams#6928kt3k merged 18 commits intodenoland:mainfrom
Conversation
|
Sorry, I'm quite inexperienced in deno std. Looking at YAML parsing in the std it uses SyntaxError for malformed input. So instead of: you could do: ...and so on. Then, when the caller makes a mistake you could opt for TypeError. So instead of: you could do: ...and so on |
|
This is ready to be reviewed btw. The only failing test is the pull request title |
|
Thanks for the PR and sorry for the delay in review. I'm not sure if this should be an independent package. Would it make sense to include it under |
Maybe. I can move it there if everyone thinks that's better |
|
I vote for placing it in |
|
@BlackAsLight is there a reason why you chose to only support streams but not iterators? |
The preferred use case is via the .from method which returns a ReadableStream instead of an instance of itself. ReadableStreams are already iterators. The multipart/form-data media type isn't the same as other file formats as you need information within the headers to correctly decode it. These streaming classes aren't TransformStreams like Tar and Cbor offers but instead meant to be the start or end of a streaming process. |
| /** | ||
| * The value of the form data entry. | ||
| */ | ||
| value: ReadableStream<Uint8Array>; |
There was a problem hiding this comment.
I meant that I would want to pass an (async) iterator here without first having to convert it to a stream
There was a problem hiding this comment.
Did you mean this line: https://github.com/denoland/std/pull/6928/changes/BASE..637c16fcb6c6b3058e2f323d474c351248959fe8#diff-9a727642d87d2fe68db223e18e8d935be3dd5a12031a1de01657571e9467a412R21
If so, simply for simplicity. One can do ReadableStream.from to convert an iterator or async iterator to a stream. Even if I changed the type, it would just move it to me wrapping it in a stream instead of you.
Asking for a stream specifically instead of an iterator also means I can take advantage of byob if it is available. Although if I'm being honest, the lack of support for a byob stream to continue being byob through a TransformStream is disappointing.
This pull request introduces a new package (
@std/formdata), offering a way to process FormData content in a streaming manner. It is based off the RFC 7578 spec.When a website submits a standard HTML form, it is sent using the multipart/form-data content type. Currently, servers must wait until the entire payload has been received before any processing can begin, which often forces them to impose strict size limits and rely on client-side JavaScript to handle larger uploads. This pull request addresses that limitation by enabling servers to process large uploads incrementally, without requiring JavaScript on the client, and even allowing it to be completely disabled.
Example