Added a null check and a call to read in the pre method to deal with …#6
Added a null check and a call to read in the pre method to deal with …#6oferns wants to merge 1 commit intoevil-dr-nick:masterfrom
Conversation
…streams that have not started to be read yet
|
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 ? |
|
fixes #5 |
|
I am passing the result of HttpResponseMessage.Content.ReadAsStreamAsync() directly to the constructor of Utf8JsonStreamreader. |
|
I will add a test but its friday night So It'll have to be over the weekend. |
|
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. 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. |
…streams that have not started to be read yet