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

Feat/reduce memory use for authorizer #82

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,18 @@ func (a *authorizer) NewAuthenticator(body io.Reader) (Authenticator, io.Reader)
// from the passed body stream.
// When body is seekable, use seek to reset the streams
// cursor to the start.
// If the body is a bytes.Buffer, create a new buffer and perform a shallow copy
// of the original buffer's content to the new one. Use the new buffer for retries.
// Otherwise, copy the stream into a buffer while uploading
// and use the buffers content on retry.
if _, ok := retryBuf.(io.Seeker); ok {
switch body.(type) {
case io.Seeker:
body = io.NopCloser(body)
} else {
case *bytes.Buffer:
buffer := &bytes.Buffer{}
*buffer = *body.(*bytes.Buffer)
retryBuf = buffer
default:
buff := &bytes.Buffer{}
retryBuf = buff
body = io.TeeReader(body, buff)
Expand Down
Loading