{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/AspNetCore/issues/15063","repository_url":"https://api.github.com/repos/aspnet/AspNetCore","labels_url":"https://api.github.com/repos/aspnet/AspNetCore/issues/15063/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/AspNetCore/issues/15063/comments","events_url":"https://api.github.com/repos/aspnet/AspNetCore/issues/15063/events","html_url":"https://github.com/aspnet/AspNetCore/issues/15063","id":507964305,"node_id":"MDU6SXNzdWU1MDc5NjQzMDU=","number":15063,"title":"Asp.net core 3.0 how read body from PipeWriter . ","user":{"login":"mkris2003","id":7632468,"node_id":"MDQ6VXNlcjc2MzI0Njg=","avatar_url":"https://avatars0.githubusercontent.com/u/7632468?v=4","gravatar_id":"","url":"https://api.github.com/users/mkris2003","html_url":"https://github.com/mkris2003","followers_url":"https://api.github.com/users/mkris2003/followers","following_url":"https://api.github.com/users/mkris2003/following{/other_user}","gists_url":"https://api.github.com/users/mkris2003/gists{/gist_id}","starred_url":"https://api.github.com/users/mkris2003/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkris2003/subscriptions","organizations_url":"https://api.github.com/users/mkris2003/orgs","repos_url":"https://api.github.com/users/mkris2003/repos","events_url":"https://api.github.com/users/mkris2003/events{/privacy}","received_events_url":"https://api.github.com/users/mkris2003/received_events","type":"User","site_admin":false},"labels":[{"id":1119602498,"node_id":"MDU6TGFiZWwxMTE5NjAyNDk4","url":"https://api.github.com/repos/aspnet/AspNetCore/labels/area-servers","name":"area-servers","color":"5319e7","default":false},{"id":85297674,"node_id":"MDU6TGFiZWw4NTI5NzY3NA==","url":"https://api.github.com/repos/aspnet/AspNetCore/labels/question","name":"question","color":"cc317c","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2019-10-16T16:35:51Z","updated_at":"2019-10-22T19:49:31Z","closed_at":null,"author_association":"NONE","body":"  \r\nHi,\r\n\r\nCould you please help me i am writing middleware for request and response .\r\n\r\ni was using  stream but need to convert  PipeWriter and PipeReader.\r\n\r\n\r\n\r\nCould you please help me how read body from PipeWriter .\r\n\r\n\r\n\r\ni have written code for PipeReader.\r\n\r\nprivate  async Task<string> GetStringFromPipeReader(PipeReader reader)\r\n        {\r\n            StringBuilder stringBuilder = new StringBuilder();\r\n            while (true)\r\n            {\r\n                // await some data being available\r\n                ReadResult read = await reader.ReadAsync();\r\n                ReadOnlySequence<byte> buffer = read.Buffer;\r\n                // check whether we've reached the end\r\n                // and processed everything\r\n                if (buffer.IsEmpty && read.IsCompleted)\r\n                    break; // exit loop\r\n               \r\n                // process what we received\r\n                foreach (var segment in buffer)\r\n                {\r\n                    string asciString = Encoding.ASCII.GetString(\r\n                        segment.Span);\r\n                    stringBuilder.Append(asciString);\r\n                }\r\n                // tell the pipe that we used everything\r\n               // reader.AdvanceTo(buffer.End);\r\n\r\n                reader.AdvanceTo(buffer.Start, buffer.End);\r\n\r\n                if (read.IsCompleted)\r\n                {\r\n                    break;\r\n                }\r\n\r\n            }\r\n            return Convert.ToString(stringBuilder);\r\n        }\r\n\r\n       private  async Task  WriteSomeDataAsync(PipeWriter writer, string jsonValue)\r\n        {\r\n            // use an oversized size guess\r\n            Memory<byte> workspace = writer.GetMemory();\r\n            // write the data to the workspace\r\n            int bytes = Encoding.ASCII.GetBytes(\r\n               jsonValue, workspace.Span);\r\n            // tell the pipe how much of the workspace\r\n            // we actually want to commit\r\n            writer.Advance(bytes);\r\n            // this is **not** the same as Stream.Flush!\r\n            await writer.FlushAsync();\r\n        }\r\n\r\nThanks,\r\nKonanki"},"comment":{"url":"https://api.github.com/repos/aspnet/AspNetCore/issues/comments/545124346","html_url":"https://github.com/aspnet/AspNetCore/issues/15063#issuecomment-545124346","issue_url":"https://api.github.com/repos/aspnet/AspNetCore/issues/15063","id":545124346,"node_id":"MDEyOklzc3VlQ29tbWVudDU0NTEyNDM0Ng==","user":{"login":"davidfowl","id":95136,"node_id":"MDQ6VXNlcjk1MTM2","avatar_url":"https://avatars3.githubusercontent.com/u/95136?v=4","gravatar_id":"","url":"https://api.github.com/users/davidfowl","html_url":"https://github.com/davidfowl","followers_url":"https://api.github.com/users/davidfowl/followers","following_url":"https://api.github.com/users/davidfowl/following{/other_user}","gists_url":"https://api.github.com/users/davidfowl/gists{/gist_id}","starred_url":"https://api.github.com/users/davidfowl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidfowl/subscriptions","organizations_url":"https://api.github.com/users/davidfowl/orgs","repos_url":"https://api.github.com/users/davidfowl/repos","events_url":"https://api.github.com/users/davidfowl/events{/privacy}","received_events_url":"https://api.github.com/users/davidfowl/received_events","type":"User","site_admin":false},"created_at":"2019-10-22T19:49:31Z","updated_at":"2019-10-22T19:49:31Z","author_association":"MEMBER","body":"@mkris2003 There's no point using the PipeReader if you're going to turn it all into a string. You won't save too much (though you can save on intermediate allocations). You're basically re-implementing StreamReader at that point."}}
{"actor":{"display_login":"davidfowl"}}