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

Add async methods for creating Reader object #44

Closed
wants to merge 2 commits into from
Closed

Add async methods for creating Reader object #44

wants to merge 2 commits into from

Conversation

Quppa
Copy link
Contributor

@Quppa Quppa commented Mar 31, 2018

Implements #11

byte[] bytes;

// If the stream is within "int" max size, we can read it at once without requiring MemoryStream
if (stream.CanSeek && stream.Length <= int.MaxValue)
Copy link

@niemyjski niemyjski Mar 31, 2018

Choose a reason for hiding this comment

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

These checks need to be removed or updated. We aren't seeking any stream positions and calling stream.Length I believe will go out and buffer entire stream contents to get the length (it isn't cheap). If we are going to do this, we should see if the stream is a MemoryStream first :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This branch was added as part of #38 - I added the additional check for bytesRead != stream.Length on lines 57 and 97 because Read/ReadAsync aren't guaranteed to fill the buffer with the requested number of bytes (I guess the likelihood of that depends a lot on the type of Stream one passes in).

I'm happy to just use the MemoryStream implementation, but I'm curious to hear @maartenba's thoughts on the matter.

Potentially replacing the ToArray call with TryGetBuffer is a good idea.

Choose a reason for hiding this comment

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

Yeah, I'm just saying calling length is not a good idea on any stream (minus in memory) as it will cause the whole stream to be consumed to get the length.

@niemyjski
Copy link

LGTM

@oschwald
Copy link
Member

oschwald commented Apr 2, 2018

Thanks! This looks good to me. I'd also be curious to hear @maartenba's thoughts on this.

oschwald added a commit that referenced this pull request Dec 18, 2018
@oschwald
Copy link
Member

Thanks! I merged this from the command line. I apologize for leaving this open for so long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants