Skip to content

Added a null check and a call to read in the pre method to deal with …#6

Open
oferns wants to merge 1 commit intoevil-dr-nick:masterfrom
oferns:master
Open

Added a null check and a call to read in the pre method to deal with …#6
oferns wants to merge 1 commit intoevil-dr-nick:masterfrom
oferns:master

Conversation

@oferns
Copy link

@oferns oferns commented Feb 28, 2020

…streams that have not started to be read yet

…streams that have not started to be read yet
@evil-dr-nick
Copy link
Owner

What is your use case here? Are you reading a single object from the stream - if so, this isn't a particularly efficient way to do so.

Can you please add a test that illustrates the use case and requires the fix ?

@evil-dr-nick
Copy link
Owner

fixes #5

@oferns
Copy link
Author

oferns commented Feb 28, 2020

I am passing the result of HttpResponseMessage.Content.ReadAsStreamAsync() directly to the constructor of Utf8JsonStreamreader.

@oferns
Copy link
Author

oferns commented Feb 28, 2020

I will add a test but its friday night So It'll have to be over the weekend.

@evil-dr-nick
Copy link
Owner

Clearly you're passing the stream to the constructor of Utf8JsonStreamReader, since that is the only way to get it in there, but then what ?

If you're doing this simply to read a single document from the stream I would suggest using JsonDocument.Parse or JsonDocument.ParseAsync directly - it would be simpler and more efficient.

The intention of this class is to support reading multiple objects from a stream so you don't blow up memory trying to read the entire thing at once.
So you would typically have something like:
[ { ... first json object }, { ... second json object }, ... ]

and would then typically call Read twice - once to read the array start, once to read to the first object start. Then you read the body of the object. So you wouldn't get the situation you're trying to fix.

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