Repository navigation
Conversation
The chunked multipart encoder wrote a file part that responds to #size as one chunk of that size, so an empty file wrote the last chunk and a partly read file declared more bytes than it sent. Remove that branch so that every file part goes through the loop that sizes each chunk by the bytes actually read. Co-authored-by: Orien Madgwick <vcs@orien.io> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pass a Chunker to encode_multipart_form_data instead of framing chunks there, as ruby#330 does for file parts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A zero-size chunk marks the end of a chunked body, so Chunker#write must not emit one for an empty string. IO.copy_stream passes an empty string when the source's read returns one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each block read from a file part is written as one chunk when the body is chunked, so larger blocks reduce the number of chunks and writes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This combines and replaces #330 and #373, and also makes chunked multipart uploads faster by reading file parts in larger blocks.
When a multipart form is sent with
Transfer-Encoding: chunked, a file part that responds to#sizeis written as a single chunk of that size. An empty file then writes a zero-size chunk, which ends the body, and a partly read file declares more bytes than it sends.Changes
#sizebranch, so that every file part is framed by the bytes actually read. The test is based on the one in Fix chunked multipart bodies with empty or partly read files #373.Chunker, as Frame multipart file chunks from the bytes actually copied #330 does for file parts.Chunker#writeskip empty strings, because a zero-size chunk ends the body.IO.copy_streampasses an empty string when the source'sreadreturns one.Performance
A 300 MB chunked multipart upload over loopback (median of 60 runs):
With 4 KB blocks, the same upload took about 1.4 s over HTTP.