uploads: использовать streaming upload для reader с известным размером#133
Open
ppmaskaluk wants to merge 1 commit intomax-messenger:mainfrom
Open
uploads: использовать streaming upload для reader с известным размером#133ppmaskaluk wants to merge 1 commit intomax-messenger:mainfrom
ppmaskaluk wants to merge 1 commit intomax-messenger:mainfrom
Conversation
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.
Summary
UploadMediaFromReader*иUploadPhotoFromReader*на уже существующий streaming path, если размер входного reader известенContent-LengthвUploadMediaFromUrlиUploadPhotoFromUrl, чтобы не собирать multipart body целиком в памяти без необходимостиЧто исправляет
Сейчас reader-based upload всегда собирает multipart body целиком в
bytes.Buffer, даже если входной поток уже имеет известный размер. Это приводит к лишней буферизации в памяти при загрузке больших файлов.После этого изменения библиотека переиспользует уже существующий
uploadMediaFromReaderWithSizeдля*os.File,strings.Reader,bytes.Reader,bytes.Bufferи других reader, у которых можно определить размер черезLen()илиio.Seeker.Это снижает пиковое потребление памяти и уменьшает риск OOM/долгих GC-пауз, не меняя публичный API.
Проверка
go test ./...