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

remove lenreader & add unit tests #28

Merged
merged 1 commit into from
Dec 2, 2022
Merged

Conversation

tarunKoyalwar
Copy link
Member

Description

// LenReader is an interface implemented by many in-memory io.Reader's. Used
// for automatically sending the right Content-Length header when possible.

type LenReader interface {
	Len() int
}

io.TeeReader does not follow/implement LenReader hence ReusableReadCloser always fails with LenReader .

  • Added Unit Test to test compatiblility

@tarunKoyalwar tarunKoyalwar self-assigned this Dec 1, 2022
@tarunKoyalwar
Copy link
Member Author

Replacement for LenReader

// getLength returns length of a Reader efficiently
func getLength(x io.Reader) (int64, error) {
	len, err := io.Copy(io.Discard, x)
	return len, err
}

Copy link
Member

@Mzack9999 Mzack9999 left a comment

Choose a reason for hiding this comment

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

lgtm!

@Mzack9999 Mzack9999 merged commit 471a54f into main Dec 2, 2022
@Mzack9999 Mzack9999 deleted the readerutil-test-cases branch December 2, 2022 05:46
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